Results Binding in a Text Widget


Do you have dashboards that are not tied to a specific timeframe? Or is your imports to Einstein Analytics not done on a daily basis? How do your users know what time period they are looking at data from? Well, I have a way for you to easily portray this to your users using two hidden steps and result binding.

I have a very simple dashboard with just one step # Trips; however, the user cannot see the timeframe of the data. So I want to add a text widget with this information. As mentioned above I need to create two hidden steps; one calculating the first day and one calculating the last day.

Hidden Step: First Date

First, let’s create a new step to the dashboard; I’ll choose my trip dataset.

We need to group the dataset by a date field (Year-Month-Day), in my case Start Date.

Now I want to switch to SAQL mode by clicking >_ in the top right corner. As you can see our changes has already been applied to the SAQL, but we need to do a little bit more, we need to limit our result to 1. So simply change 2000 to 1. Also, we want to change the date field to avoid the standard “~~~” and just use “-“. Finally, click “apply”. You should expect something like this:

q = load "trip";
q = group q by ('start_date_Year', 'start_date_Month', 'start_date_Day');
q = foreach q generate 'start_date_Year' + "-" + 'start_date_Month' + "-" + 'start_date_Day' as 'start_date_Year-start_date_Month-start_date_Day', count() as 'count';
q = order q by 'start_date_Year-start_date_Month-start_date_Day' asc;
q = limit q 1;

Before clicking done remember to give your new step a relevant name, so it’s easy to find later. I’ve called mine FirstDateSAQL.

Hidden Step: Last Date

For the second hidden step we will simply clone the step we just created. The only thing we need to modify is the order; instead of “asc” put “desc” and click “apply”. Your step should look something like this:

q = load "trip";
q = group q by ('start_date_Year', 'start_date_Month', 'start_date_Day');
q = foreach q generate 'start_date_Year' + "-" + 'start_date_Month' + "-" + 'start_date_Day' as 'start_date_Year-start_date_Month-start_date_Day', count() as 'count';
q = order q by 'start_date_Year-start_date_Month-start_date_Day' desc;
q = limit q 1;

Before finishing and clicking done rename your step. I’ve called mine LastDateSAQL.

Result Binding

The last part is to tie it all together in a text widget. So I’ll add a text widget to my dashboard and populate the text with “This is showing data from A to B”.

Please note the ID of the text widget, in my case “text_2”. Now we need to switch to the JSON (Command+E or Ctrl+E) and modify widget.

In the Widget section of your dashboard JSON find your version of “text_2”. We need to modify the “text” parameter of the widget and add the result binding to the string using this structure.

{{column(STEP_NAME.result, ["FIELD_NAME"]).asObject()}}

First, replace “A” with the following result binding:

{{column(FirstDateSAQL_1.result, ["start_date_Year-start_date_Month-start_date_Day"]).asObject()}}

Next, replace “B” with a similar result binding:

{{column(LastDateSAQL_1.result, ["start_date_Year-start_date_Month-start_date_Day"]).asObject()}}

For both of them remember to change the date to the date field you have used.

The text widget should now look something like this:

"text_2": {
 "parameters": {
 "fontSize": 20,
 "text": "This is showing data from {{column(FirstDateSAQL_1.result, ["start_date_Year-start_date_Month-start_date_Day"]).asObject()}} to {{column(LastDateSAQL_1.result, ["start_date_Year-start_date_Month-start_date_Day"]).asObject()}}",
 "textAlignment": "left",
 "textColor": "#335779"
 "type": "text"

That’s it! Now preview your dashboard and see that “A” and “B” has been replaced with the first date and the last date.

How useful was this post?

Click on a star to rate useful the post is!

Written by

3 thoughts on “Results Binding in a Text Widget”

  • 1
    Abhinav Garg on October 6, 2018 Reply

    Is It possible to get the addition of two number widget in third number widget?
    I’ve tried the approach as you mentioned in the blog but doesn’t work numbers. Please advise.

    • 2
      Rikke on October 6, 2018 Reply

      You could create a compare table with your calculation and use that in your number widget – no need to use bindings.

  • 3
    Sarang on December 31, 2018 Reply

    Any way we can format the result. In your example, the value shows in million and I am looking to shorten the value and present like “$1.3M”

Leave a Reply

Your email address will not be published.

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