Field usage analysis

I cannot tell you how excited I am to be writing this blog and I think you will find this immensely helpful especially if you have had Tableau CRM (formerly Einstein Analytics) for a while. I find many users end up creating a lot of dataflows and bringing in a lot of fields because they can. Down the line these dataflows become slow and you start looking at how to optimize them. Well, one of the easiest ways to improve performance is to remove the fields that are not being used (doh!) however it’s not always that simple to figure out which fields you can remove. So Mohan Chinnappan has made this available in his SFDX plugin and added the fieldUsage command. The new command is part of the functionality of an earlier private chrome extension, however, this is not the only time the field usage problem has been tackled, work has been seen by Jason Huffman and Sagar Varma. Sagar’s solution even inspired taking the field usage analysis further making sure a csv could be loaded back into Tableau CRM to get a visual representation. Let’s have a look at how this new command works and how you can:

  • generate a csv file with all the fields in a dataflow
  • see if a field is used in a lens, dashboard or security predicate
  • create a dashboard of your dataflow field usage.

Get the plugin

I’ve previously gone through installing the plugin, so instead of walking through how to do that please refer to the Export your Einstein Analytics datasets blog.

Note: You need to both install the Salesforce CLI and Mohan’s plugin to continue to benefit from this blog. Check out the steps in Export your Einstein Analytics datasets.

If you already have the plugin you may very well need to update it to get the latest version. For my demonstration in this blog, I am using Apple’s terminal.

In Terminal we want to run the following command to update all the plugins.

sfdx plugins:update

Once this is done you can check the version of the installed plugins by using the following command:

sfdx plugins

As you can see the version I am using for this blog is 0.0.73, however, you may discover more updates have been made available and you have a later version.

Note: Check out the latest enhancements to fieldUsage in Github.

The fieldUsage command

The new command that has been added is the fieldUsage, so let’s have a look. To get the options for this command in terminal you can add the following command:

sfdx mohanc:ea:dataflow:fieldUsage -h

Let’s have a closer look at the options for this command.

Username

Use the -u option to specify a username to use for your command.

--The option
sfdx mohanc:ea:dataflow:fieldUsage -u <insert username>

--Example
sfdx mohanc:ea:dataflow:fieldUsage -u rikke@demo.org

Dataflow id

Use the -d option to specify a dataflow id to use for your command.

--The option
sfdx mohanc:ea:dataflow:fieldUsage -u <insert username> -d <insert dataflow id>

--Example
sfdx mohanc:ea:dataflow:fieldUsage -u rikke@demo.org -d 02K3h000000MtyuEAC

The dataflow list command

To use the fieldUsage command we need to have a dataflow id, which we can get by using the dataflow list command. To get the option for this command enter the following:

sfdx mohanc:ea:dataflow:list -h

Let’s have a closer look.

Username

Use the -u option to specify a username to use for your command.

--The option
sfdx mohanc:ea:dataflow:list -u <insert username>

--Example
sfdx mohanc:ea:dataflow:list -u rikke@demo.org

Extract the field usage

There is a prerequisite to be using this command, we need to know the dataflow id as you may have guessed when walking through the command options from before. Once we have that we are able to leverage the fieldUsage command. Finally, you will see that we get an output csv file we can use to import into Tableau CRM in order to visually display the field usage. However, before getting started make sure you are logged into your org.

Note: Before using the load command you would have to log in to the desired org by using the command sfdx force:auth:web:login, which will launch the login window in a browser.

Find dataflow id

As mentioned we need to find the dataflow id we want to use for our check. Hence we are going to use mohanc:ea:dataflow:list command, which is pretty simple as we only have to define the target org via the username.

Step 1 – use the dataflow:list command to extract the list of dataflows in the org.

sfdx mohanc:ea:dataflow:list

Step 2 – define the username for the target org by adding the -u option.

sfdx mohanc:ea:dataflow:list -u rikke@discovery.gs0

Step 3 – press enter.

Step 4 – find your the dataflow in question, copy the id and save it somewhere. I’m just adding mine to a text editor.

Check field usage

Next let’s look at how to check the field usage for the dataflow we picked in the steps above.

Step 1 – use the fieldUsage command from the plugin.

sfdx mohanc:ea:dataflow:fieldUsage

Step 2 – define the username for the target org by adding the -u option.

sfdx mohanc:ea:dataflow:fieldUsage -u rikke@discovery.gs0

Step 3 – define the dataflow to check by adding the -d option and use the id from the previous steps.

sfdx mohanc:ea:dataflow:fieldUsage -u rikke@discovery.gs0 -d 02KB0000000BRisMAG

Step 4 – press enter.

Step 5 – wait for the fieldUsage command to run and you will notice two files being generate a json and a csv file. You can copy the name and search for the file on your computer. You can ignore the json file and keep the csv file.

Step 6 – if you open the csv file you will find each field from the dataflow as well as the dataset name and if it’s used and where (dashboard, lens and security predicate).

Load field usage

We got the usage, but why stop here? Let’s load the csv file back into Tableau CRM as a dataset, so we can create a nice dashboard illustrating the field utilization and of course which fields might make sense to remove.

Note: To get more details on how the load command works please check out the blog Uploading datasets via CLI.

Step 1 – make sure the name of your csv file will not exceed 18 characters when uploaded. If it will rename the file – I’m calling mine fldusage.csv.

Step 2 – use the load command from the plugin.

sfdx mohanc:ea:dataset:load

Step 3 – define the username to use by adding the -u option.

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0

Step 4 – define what csv file and it’s location to use by adding the -d option.

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0 -d Desktop/fldusage.csv

Step 5 – press enter.

Step 6 – create a dashboard to see your field usage for your dataflow.

What more?

If you have many dataflows and you want to check the field usage from more than just one, you can use the fieldUsage command for the desired dataflows, you can then load the csv files but in the load command use the append operation to have one dataset with all the dataflows and datasets. Check out the Uploading datasets via CLI blog for more details on how to append your csv to a dataset during the load.

If you have any feedback or suggestions for the fieldUsage command please leave a comment on the blog. In the meantime, Mohan is continuing to develop new functionalities to the plugin incl. a dataflow visualization command to document what is happening in each node (sneak preview below).


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.