Categories
Blog Salesforce

Einstein Analytics Applications, create/update templates

Did you create your first Einstein Analytics application? Clean and neat! I assume that you’ve already designed a data flow, ran it already to generate your application dataset. Created a dashboard with lenses in place, filters, lists, charts to visualise the dataset.

It’s already great, now you can go to Einstein Analytics, click on your application. Check the charts, read your data, understand it easier than before. Read any change at a glance, easy peasy. You answered your own questions with it but there are many people out there who are struggling with the same problems. What’s next?

Well, you can share your solution with them from A to Z. However, you first need to create a template. Here is how! 

At this step if you have no clue about what are the templates, go ahead and watch these two short videos.
Einstein Analytics Templates: Build, Customize. Sell.

Before you start, you need to make sure that all the prerequisites are set correctly. If you are not sure take a quick look at this page 🌍.

Well, after the making sure that all prerequisites are on place, go to https://workbench.developerforce.com/ and logging in to your org.

Check out the Step 1 to Create (or Update) the Template Objects then you follow the next steps according to the interests of your Einstein Analytics applications.

If you need to define rules or create a wizard for your Einstein Analytics application then it’s possible to change this by following Step 3 to Edit the JSON Files.

For example, the wizard is how you ask your future template user to decide which dimensions in a dataset to include and which to exclude, what name a new dashboard, or how to label a field in a chart. You control all this by editing the four types of JSON files discussed in this step (template-info.json, ui.json, variables.json, and any number of rules.json), which constitute the template assets.

Categories
Blog Salesforce

Variance Analysis using Einstein Analytics (Wave Analytics)

In order to create more insight on sales data, Einstein Analytics can be great help. In order to bring Einstein Analytics into the game, it’s required to create relevant data flows, datasets, dashboards in other words an EA application.

The aim here is to bring a solution for better understanding the relations between profitability/loss at first sight. In order to achieve this goal, daily data collection is important, this means running the data flow everyday and get the ‘exchange rate’, ‘price of the products’, ‘partial and/or total volumes’ and naturally the ‘revenue’ and ‘date’. Basically take a snapshot of the data.

The data flow runs daily and stores the data in a table. The data table grows by addition of new rows. The data table also includes ‘snapshot date’, ‘exchange rate’, ‘price’, ‘volume’ and ‘revenue’ fields as columns. 

In order to calculate the changes shown in the figure above, you need to use the compare table. 

when you edit a lens in the dashboard,
choose ‘compare table’

You need to add measures then click on the ‘arrow down’ icon and select ‘Edit this column’ option of a measure to define formulas for the column.

add new measures and edit them

While editing the columns (measures) you can assign new aliases. For example in the use case which is defined here, one can expect two snapshots having two different revenue values and a new column to calculate the ‘change in revenue’. It’s easy to set the alias R1 for ‘snapshot #1’s revenue’ as R2 for ‘snapshot #2’s revenue’. It’s simple! Defining the ‘change in revenue’ requires a new column with a formula calculation of ‘R2-R1’.  You can also define window functions for different groups of data.

give alias, column names and define formulas when
editing the columns of the compare table

Once you have all the columns and their formulas defined, you can save the compare table and transform it into a chart. The calculations are done, dynamically and displayed as bars, slices or as gauges according to your chart choices.

Problem: I guess until this point everything was clear. The problem I was facing with was to define two date fields (as string) ‘Snapshot Date 1’ and ‘Snapshot Date 2’ and filter the data ‘Revenue’, ‘Price’ etc. on selection. 

The tricky part was having only one table (dataset). So I defined two columns for date (as string) which are calculated (computeExpression) everyday when the data flow run happens.

When you use one field ‘Snapshot Date 1’ and select a date, because of faceting, every element on the dashboard was filtered. This restricts comparison of two dates.

Overcoming such a problem requires ‘disabling faceting’ on the list selector fields and on the chart and define manual binding of the fields as filters to the steps. 

revenue comparisons for two different snapshot dates

Solution: I basically modified the compare table, disabled the faceting and bound the steps with list selectors in a custom fashion. The bottle neck was the binding filters and the steps.

To do that hit Ctrl+E (windows), Cmd+E (mac) and edit the code as below for each column you want to filter per list selector.

"filters": [
  [
      "SnapshotDate1",
      [
          "{{column(SnapshotDate1ListSelector.selection, [\"SnapshotDate1\"]).asObject()}}"
      ],
      "=="
  ]
]

In order to make the binding happen and filtering work, the real trick was using “==” operator rather than “in”.

Categories
Salesforce

Custom (re)ordering of legend/bar segments in Einstein Analytics

Problem:

Recently I tacked with the problem of ordering the legend/bar segments in Einstein Analytics and this is how I solved it.

Using the Einstein Analytics user interface, I could sort bar segments of a stacked column chart in asc/desc order or keep it unsorted. However, I needed to sort them in a custom fashion like in the image. 

Apparently, its possible by using custom SAQL and with final touches using the extended meta data a.k.a XMD.

Solution:

if you are familiar with Einstein Analytics, you know this one 😉

Then you need to add a similar code like the following into the SAQL code:

q = foreach q generate (case 
when 'Fruits__c' == "Berry" then "03 Berry" 
when 'Fruits__c' == "Apple" then "02 Apple" 
when 'Fruits__c' == "Orange" then "01 Orange" 
end) as 'Fruits__c';

After this step, the legend is going to show its contents with numbers in front. To fix this using the eXtended Meta Data (XMD) .json file.

Go ahead download the XMD.json file after clicking “edit” dataset. As seen in the screenshot below, click “download” to get the latest .json file.

you will see it, when you click ‘edit’ dataset

Now you need to edit the “dimensions” part like in the example code below. Define the member and label fields, if you want to override the color as well then also color too.

Next step is to replace the XMD .json file. Click the ‘replace‘ button and upload the updated file.

{"dataset":{},"dates":[],"derivedDimensions":[],"derivedMeasures":[],
    "dimensions" : [
  {  
    "field":"Fruits__c",
    "linkTemplateEnabled": false,
    "members":[  
      {  
        "color":"#EB271F",
        "label":"Orange",
        "member":"01 Orange"
      },
      {  
         "color":"#F7B92B",
         "label":"Apple",
         "member":"02 Apple"
      },
      {  
         "color":"#FD9226",
         "label":"Berry",
         "member":"03 Berry"
      }
    ],
    "recordDisplayFields": [],
    "salesforceActions": [],
    "salesforceActionsEnabled": false,
    "showInExplorer": true
  }
],"measures":[],"organizations":[],"showDetailsDefaultFields":[]}

Niceness! Now you have an ordered/coloured legend/bar segments in the stacked column chart and no more misleading/confusing numbers in front the legend elements.

Categories
Salesforce

Einstein Analytics Building a Data Flow

Before you start with this post, make sure that you already read “Salesforce Einstein Analytics” post.




Here we are climbing the steps of building a dataset by forming our very first dataflow. Don’t forget, it all starts with data and it’s better to have data of good quality. If you know the data that you’re working on, if you understand it well then Einstein Analytics will make your data easy peasy for you to interpret and visualize. In other words, make sure you know what to achieve with your data and have a good use case in hand, for validation and testing purposes.

Put your hands in the air, then on the keyboard & trackpad. 🙂 We are good to go.

Remember the ‘create‘ button? You should be also remembering the SampleDataset and SampleDataflow titles. Next step is to pick the Salesforce or custom objects you have in the org and the fields that you want to include in the dataflow. When you click on it, the wizard will already take you to the next step.

Now it is time to click on the object (the initial selection) and pick the fields you want to use (to be included in the dataset) also select the connections to other Salesforce standard or custom objects. You can select Fields and Relationships and each join click will make you access to another object and its fields. The wizard is a great help to get any field and object in the org.

Einstein Analytics team together made it really handy. If you already know the objects you are going to work with, simply selecting the parent (the top object) will give you an advantage. Joining a new object and selecting new fields will be simple clicks.




Go ahead! Play with the wizard, experiment, fail, break and learn how to use it with confidence and success. You can select the main node of the tree then add branches, like in this example. Once you are done with the wizard, you need to navigate and click Next.






When you are done with the selections and click next, then your dataflow will be prepared by the wizard for an easier data engineering progress. Dataflow manager will generate the simple and complex dataflow, with respect to your selections. The dataflow may look like the screenshot below, but this screenshot is not the best possible one. It may differ with every other dataflow preperation.

Now we can get our hands dirty and dive into the world of manual dataflow manipulations, changes, fixes and building brand new dataflows from scratch. I hope you already are familiar with Transformations for Analytics Dataflows, if not check the post I linked above.

To be continued…