Pages

Sunday, August 5, 2018

Einstein Analytics: Dashboard API Name

As usual Salesforce stuff, we have label and name (read API name) for an object, field, dashboard, and etc. But, is there such things in the Einstein Analytics? Yes, there is, although you do not always need to know the API name, however, in some scenario, you need to know.

When you edit a dashboard, you only change the title, same goes to the lens. Let looks at dashboard JSON, the second line of the dashboard will say "label": "dashboard name", we can easily change the label, but how to change the API name?

Scenario: I create a dashboard called "backup map", by default the API name would be backup_map, this is just by replacing space with _.
After a while, I change the label from "backup map" to "my map", will the API name change from backup_map to my_map? The answer is No.


1. Use Link Widget
Create a new dashboard, add link widget and select link to Saved dashboard, and select the dashboard you would like to check.



Now, open dashboard JSON, and looks for link_1 (for this sample) widget, here we go:
       "widgets": {
            "link_1": {
                "type": "link",
                "parameters": {
                    "destinationType": "dashboard",
                    "includeState": false,
                    "text": "Button title",
                    "textColor": "#44A2F5",
                    "textAlignment": "center",
                    "fontSize": 12,
                    "destinationLink": {
                        "name": "backup_map"
                    }
                }
            }
        },


2. Workbench
Workbench is a powerful tool, love by all Salesforce developer and admin, also for us as Einstein Analytics power user.

Once you login to Workbench, navigate to utilities - REST Explorer, change the URI to /services/data/v43.0/wave/dashboards then click Execute button, then click Expand All link. Here, you will find everything you need to know about your dashboards.



You can evaluate other stuff in Einstein Analytics by changing the URI to /services/data/v43.0/wave/





Salesforce Lightning: Log a Call button does not appear in Activity component

For those of you have been migrated from Classic to Lightning, you notice that "Open Activities" and "Activity History" are no longer appeared in the related list, instead, they appear as a Ligthning component called Activity. Log a Call, New Task, and New Event will not show as buttons anymore, but as tabs under Activity component, as they appear as a component, users can enter the data without leaving the main detail page.


However, if you don't see those tabs under Activity component, here are few things you should check:

1. Page Layout
Yes, I am referring to Classic page layout, not Lightning Page. If you have multiple page layout based on profile or record type or both. Make sure you are checking the correct page layout.

Open a record, click the gear icon, then Edit Page link, click Details tab, then click the layout in Details tab, check the page layout name with (previewed).



Now, go to that page layout -- back to the record page, click Edit Object link under the gear icon, select Page Layouts menu, then click the same page layout showed in the previewed earlier.

Select Mobile and Lightning Actions, make sure Log a CallNew Task, and New Event are added into the Salesforce Mobile and Lightning Experience Actions section.



2. Record Type
Check if you have record type defined (even only one) in Task and Event, make sure they are selected in the global action because of one action only for one record type.



Go to Global Actions under Setup menu, click edit on Log a Call, you may see this by the standard.
In the Record Type, change --Master-- to Special, and click Save button.



Now, back to the record page and check Activity component, you should see Log a Call action appear under Activity component. The same for New Task action, it should appear too once you fix the Global Action.



For New Event action (as it is Event object), check if you have Record Type defined in the Event, if yes, you need to do the same for New Event action to define the Record Type.


Reference:



Wednesday, August 1, 2018

Einstein Analytics: Connect Date Source with Date

In previous blog Connect Data Sources and Binding between Dataset, we share about using Connect Data Sources and binding to connect dataset. This blog will share tips:
- how to connect data sources between Date and Dimension.
- how to create list value using Date field


Use Case 1: Sales date is stored in Actual dataset, while Target amount is in Target dataset. We would like to show both actual and target in a dashboard when a certain month and year are selected.

Steps:
1. Target data
Load Year and Month as 2 fields, load both fields as Dimension, not as Measure (Number).

2. Add List
Add List for both Year and Month to the dashboard.

3. Connect Data Source for Month
For Data Source 1, select Month from Target -- here Month is Dimension. For Data Source 2, we can't select Date or type Date_Month from Actual (it is a Date field), so just select any Dimension field for temporary, in this sample, I select Sales_Rep. My dataset API name for Target is Text_Month, and for Actual is Sales_by_Date.


4. Edit dashboard JSON
Einstein Analytics by default will auto parse date field into many fields, e.g. FieldName_Year, FieldName_Month, FieldName_Date, and other FieldName_xxx, we can connect target Month with FieldName_Month by editing dashboard JSON, change the temporary Dimension field name Sales_Rep with Date_Month.

5. Connect Data Source for Year
From dashboard JSON, copy and paste in from Month, and change to Year as a newly connected data source.

       "dataSourceLinks": [
            {
                "fields": [
                    {
                        "dataSourceName": "Text_Month",
                        "dataSourceType": "saql",
                        "fieldName": "Month"
                    },
                    {
                        "dataSourceName": "Sales_by_Date",
                        "dataSourceType": "saql",
                        "fieldName": "Date_Month"
                    }
                ],
                "label": "Month",
                "name": "Link_4521"
            },
            {
                "fields": [
                    {
                        "dataSourceName": "Text_Month",
                        "dataSourceType": "saql",
                        "fieldName": "Year"
                    },
                    {
                        "dataSourceName": "Sales_by_Date",
                        "dataSourceType": "saql",
                        "fieldName": "Date_Year"
                    }
                ],
                "label": "Year",
                "name": "Link_4522"
            }
        ]



6. The moment of Truth




Use Case 2: Target is stored as a Date field.

Steps:
1. Add List
Add List for both Year and Month to the dashboard, you cannot select Date field for List, so just select any Dimension field temporary.

2. Edit List
Edit the List and change the Bars by selecting Date then Month for Month list, and select Date then Year for Year list.


You also can manually edit dashboard JSON, looks the query and change the group to Date_Month for month list, and Date_Year for the year list.

                "query": {
                    "groups": [
                        "Date_Year"
                    ],
                    "measures": [
                        [
                            "count",
                            "*"
                        ]
                    ]
                }

When you go back to edit the widget, notice that now it group by Date (Year) or Date (Month) for each list.



3. Connect Data Source for Month 
Because you can't select Year and Month from both target and actual, just select any Dimension field as a temporary placeholder, edit dashboard JSON and change with Date_Month for both data source. Copy from Month to Year. My dataset API name for Target is Target, and for Actual is Sales_by_Date.

            {
                "name": "Link_2009",
                "label": "Date_Year",
                "fields": [
                    {
                        "fieldName": "Date_Year",
                        "dataSourceName": "Sales_by_Date",
                        "dataSourceType": "saql"
                    },
                    {
                        "fieldName": "Date_Year",
                        "dataSourceName": "Target",
                        "dataSourceType": "saql"
                    }
                ]
            },
            {
                "name": "Link_2010",
                "label": "Date_Month",
                "fields": [
                    {
                        "fieldName": "Date_Month",
                        "dataSourceName": "Sales_by_Date",
                        "dataSourceType": "saql"
                    },
                    {
                        "fieldName": "Date_Month",
                        "dataSourceName": "Target",
                        "dataSourceType": "saql"
                    }
                ]
            }



4. The moment of Truth





Monday, July 30, 2018

Einstein Analytics: Getting started with XMD

XMD stands for Extended Metadata, it enables you to customize the formatting of dataset fields and their values in Analytics dashboards and lenses. If you modify the XMD for a dataset, every UI visualization that uses the dataset shows the modified format.

You can customize the following with XMD:
  • Format measures. Example: Show the decimal and grouping separators for currency.
  • Add prefixes and suffixes to measures. Example: Show the percent symbol (%) after each percentage.
  • Multiply measures by a factor. Example: Multiply by 100 to convert a decimal to a percent.
  • Change display labels for dimensions and measures.
  • Customize colors in charts based on field values.
  • Define the first day of the week for the calendar year.
  • Add action menus to dimensions that let dashboard viewers invoke actions from lenses and dashboards.
Once a dataset created, by default the XMD will have no values, let's look at this. You can download XMD (which is also in JSON format) by editing the dataset.


Open the JSON file and here is the content
{"dataset":{},"dates":[],"derivedDimensions":[],"derivedMeasures":[],"dimensions":[],"measures":[],"organizations":[],"showDetailsDefaultFields":[]}

Tips: use jsoneditoronline.org to reformat the file into a human-friendly format
{
  "dataset": {},
  "dates": [],
  "derivedDimensions": [],
  "derivedMeasures": [],
  "dimensions": [],
  "measures": [],
  "organizations": [],
  "showDetailsDefaultFields": []
}


In this blog, I'll share how to rename field name with XMD for all dashboard and lenses, or in particular dashboard with SAQL.


Setup field format and label
Let us format Amount field to be in currency format $9,999.99
- Click the Dataset to open as a Lens
- Click Fields

- Set Amount format

- Rename label Amount to Initial Amount, and Region to Sales Region
- Click Save button
- Change the Lens into Values Table and now you will see Amount is in currency format with header Initial Amount and Region become Sales Region

Note that this change will change all existing dashboard and lens.



Back to XMD
Let's us re-download the XMD file and see what how it looks like now:
{
  "dataset": {},
  "dates": [],
  "derivedDimensions": [],
  "derivedMeasures": [],
  "dimensions": [
    {
      "conditionalFormatting": {},
      "customActions": [],
      "field": "Region",
      "label": "Sales Region",
      "members": [],
      "recordDisplayFields": [],
      "salesforceActions": []
    }
  ],
  "measures": [
    {
      "conditionalFormatting": {},
      "field": "Amount",
      "format": {
        "customFormat": "[\"$#,##0.00\",1]"
      },
      "label": "Initial Amount"
    }
  ],
  "organizations": [],
  "showDetailsDefaultFields": []
}

** you can use jsoneditoronline.org to re-format it.


Edit Amount with SAQL
In case that we need to change the Amount header for a particular dashboard, you can edit the lens/widget with SAQL. In this example, we are going to change from Initial Amount to MRR.
- Open the dataset with Lens
- Change to Values Table
- Click SAQL Mode button

If you notice now MRR does not have currency format we have set earlier. To enable this, we need to edit the XML file again. We need to add following conditional formatting in XMD under derivedMeasures.

A measure is a quantitative value, like revenue and exchange rate. You can do the math on measures, such as calculating the total revenue and minimum exchange rate.

Derivated measures are the ones that you get from the measures, it is calculated fields so they don’t really exist in your dataset.

{
  "dataset": {},
  "dates": [],
  "derivedDimensions": [],
  "derivedMeasures": [
  {
      "conditionalFormatting": {},
      "field": "MRR",
      "format": {
        "customFormat": "[\"$#,##0.00\",1]"
      },
      "label": "MRR"
    }
  ],
  "dimensions": [
    {
      "conditionalFormatting": {},
      "customActions": [],
      "field": "Region",
      "label": "Sales Region",
      "members": [],
      "recordDisplayFields": [],
      "salesforceActions": []
    }
  ],
  "measures": [
    {
      "conditionalFormatting": {},
      "field": "Amount",
      "format": {
        "customFormat": "[\"$#,##0.00\",1]"
      },
      "label": "Initial Amount"
    }
  ],
  "organizations": [],
  "showDetailsDefaultFields": []
}


Upload back the XMD file from Replace menu in Dataset edit. Let's reload the lens/widget.



Now realize that Amount now called MRR for the particular lens and it has current formatting too. Check Fields from Lens and now MRR is added as Derived Measures



As you see, actually we can add Derived Measures directly when you edit the dataset from the lens, without the need to edit the XMD manually.




Reference


Friday, July 27, 2018

Einstein Analytics: Chart Type Binding

In the blog shared earlier Einstein Analytics: The quest for Binding in Dashboard, we discussed in a glance that we can let user change the type of chart on the fly by using binding, it will work for most of the chart type, but not all, this is because specific chart need to have additional parameters, such as for Heatmap chart type, it requires highColor and lowColor.



Let's see the steps and sample:

1. Add a chart to the dashboard and select the initial chart type.

2. Add static step with values of chart type, such as Stack Vertical Bar, Stack Horizontal Bar, etc. You need to know the value for each chart type, sample
              "values": [
                    {
                        "display": "Stack Vertical Bar",
                        "value": "stackvbar"
                    },
                    {
                        "display": "Stack Horizontal  Bar",
                        "value": "stackhbar"
                    },
                    {
                        "display": "Heatmap",
                        "value": "heatmap"
                    },
                    {
                        "display": "Line",
                        "value": "line"
                    }
                ]

3. Change columnMap to null, you need to change only columnMap under chart/widget (not the one under the step).

4. Change visualizationType under chart/widget (not the one under the step) to {{coalesce(cell(Chart_Type_1.selection, 0, \"value\"), cell(Chart_Type_1.result, 0, \"value\")).asString()}}
** Chart_Type_1 is the step name for static step

5. For some type of charts, they required additional parameters, you need to add them, otherwise, it will not work. You can monitor the additional parameters when you add a chart with the selected chart type, some of the parameters are required, and some are not required.

all values in parameters below are for samples only

Heatmap
  "lowColor": "#E2F4FC",
  "highColor": "#009DDF",
  "x": {
          "showAxis": true,
          "showTitle": true,
          "title": ""
       },
  "y": {
          "showAxis": true,
          "showTitle": true,
          "title": ""

       }


Horizontal Bar, Vertical Bar, Stack Horizontal Bar, Stack Vertical Bar
  "trellis": {
                       "enable": false,
                       "showGridLines": true,
                       "flipLabels": false,
                       "type": "x",
                       "chartsPerLine": 4,
                       "size": [
                           100,
                           100
                        ]
             },
  "showValues": true,
  "axisMode": "multi",
  "dimensionAxis": {
                        "showAxis": true,
                        "showTitle": true,
                        "title": "",
                        "customSize": "auto",
                        "icons": {
                            "useIcons": false,
                            "iconProps": {
                                "column": "",
                                "fit": "cover",
                                "type": "round"
                            }
                        }
                    },
  "measureAxis1": {
                        "sqrtScale": false,
                        "showAxis": true,
                        "customDomain": {
                            "showDomain": false
                        },
                        "showTitle": true,
                        "title": ""
                    },
                    "measureAxis2": {
                        "sqrtScale": false,
                        "showAxis": true,
                        "customDomain": {
                            "showDomain": false
                        },
                        "showTitle": true,
                        "title": ""

                    },
  "normalize": false,

  "exploreLink": true


Line
  "showPoints": false,
  "showZero": true,
  "drawArea": {
                        "showDrawArea": false,
                        "bounding1": "",
                        "bounding2": "",
                        "measure": ""
              },
  "dashLine": {
                        "showDashLine": false,
                        "measures": ""

              },
  "exploreLink": true


Donut
  "trellis": {
                        "enable": false,
                        "showGridLines": true,
                        "flipLabels": false,
                        "type": "x",
                        "chartsPerLine": 4,
                        "size": [
                            100,
                            100
                        ]
            },
  "exploreLink": true,
  "showMeasureTitle": true,
  "centerValueType": "number",
  "centerText": "",
  "inner": 60


In summary: if your binding contains such chart type, make sure to add all of them to the parameters, especially the required parameters, otherwise, the binding for that chart type will just not working.



Tuesday, June 26, 2018

Einstein Analytics: computeRelative getting started

computeExpression is a well-known transformation tool in Dataflow, you expect to get new fields as result, based on data in the same row. While computeRelative is also transformation tool in Dataflow, but you can compare with data in the same or the other row (first, last, next, and previous).

In computeRelative, you need to specify:
- input source
- partition by field: this is unique key field such as Opportunity Id, Account Id, etc.
- sort field: this is to tell data order
- computed fields: this would be the result fields from computeRelative.

Let's use this sample dataset:


Create a dataflow using edgemart to get existing dataset in Einstein Analytics:
- add computeRelative to get Previous Amount and Previous Closed Date
- using Opportunity Id as partition field
- order by Snapshot_Date


Here is the field attribute:


In this case, we would like to leave the Previous Amount and Previous Close Date as blank if there is no previous data for the particular records. If we leave the Default Value in Field Attribute as blank, there will be no default value defined in the JSON and this will cause errors when running the dataflow.

To fix that, download the JSON file and edit it manually, then upload it back to the dataflow.

  "computeRel1": {
    "action": "computeRelative",
    "parameters": {
      "source": "EdgeProspect",
      "computedFields": [
        {
          "name": "PreviousAmount",
          "label": "PreviousAmount",
          "expression": {
            "sourceField": "Amount",
            "offset": "previous()",
            "default": null
          }
        },
        {
          "name": "PreviousCloseDate",
          "label": "PreviousCloseDate",
          "expression": {
            "sourceField": "Closed_Date",
            "offset": "previous()",
            "default": null
          }
        }
      ],
      "orderBy": [
        {
          "name": "Snapshot_Date",
          "direction": "asc"
        }
      ],
      "partitionBy": [
        "Opportunity_ID"
      ]
    }
  }


Here is the final result:




Reference: computeRelative Parameters