Pages

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.



Page-level ad