SAQL as a Second Language: Interactions

I feel like the OG Analytics person now because I can’t get away from calling them bindings, but they are actually called Interactions now. Which totally makes sense and is more clear about what it is – something that helps you interact with your data. The term binding doesn’t COMPLETELY go away because it is still part of the definition: an interaction is implemented by binding queries to each other.

As always, before you get into the SAQL or writing your own bindings, consider all of your out of the box options first. Faceting provides ready to use interactions that allow data from the same dataset to speak to each other – meaning if you select a bar in a chart or something in a list widget, data from the same dataset on your dashboard will automatically filter based on those selections. Sometimes that just isn’t possible though as we join more and more datasets to the canvas. In this example I have 3 widgets: a list selector, a donut chart and a column chart. They are all coming from the same dataset with user data.

There are two types of interactions you can use. When I’m adding interactions to dashboards, most of the time I’m using Selection Interactions. This updates a query based on the selection in another query. In almost every dashboard I make, I’m applying these types of interactions for things like currency selectors to allow users to view amounts in USD, EUR, AUD, JPY, etc. The other type of interaction you can use is a Results Interaction, which updates a query based on the results of another query. Next let’s look at the anatomy of an interaction and learn some syntax.

Interaction Anatomy

Here’s a pretty typical interaction that I use often:

{{column(currency_1.selection, ["currency"]).asObject()}}

What does that even mean?! Let’s break it down.

{{column(currency_1.selection, ["currency"]).asObject()}}

Firstly, interactions are always wrapped in two curly brackets like this {{ }}. This means its a binding/interaction.

{{column(currency_1.selection, ["currency"]).asObject()}}

The word "column" is my selection function. A selection function selects data from your source query and can be a selection or results. The function returns a table of data where each column has a name and each row has an index starting with 0. From this table, you can select one or more rows, one or more columns, or a cell. We’ll get into this more later – but for now we know that this is the selection function.

{{column(currency_1.selection, ["currency"]).asObject()}}

Next I have the name of my source query, currency_1. This is saying that I want to select some data from that query.

{{column(currency_1.selection, ["currency"]).asObject()}}

And after the name of that query, I have a .selection. This means I want a selection interaction. If I wanted a result interaction, I could do .result there instead.

{{column(currency_1.selection, ["currency"]).asObject()}}

Next I have ["currency"]. This is the column name of the data I want to select.

{{column(currency_1.selection, ["currency"]).asObject()}}

And finally, there’s an .asObject. This is the data serialization function, and converts the data into the form expected by our query. There are actually 8 different serialization functions you could apply here. .asObject passes data without serialization and just returns an array of strings. More on all of those later.

So after all that, we now know that {{column(currency_1.selection, ["currency"]).asObject()}} means this: select the column named currency from the query currency_1 and return it to me as an array of strings. That doesn’t seem so scary now right?

There is A LOT to cover with interactions in Tableau CRM. There’s even a dedicated Bindings Developer Guide, which is my best friend and something you should become acquainted with. Over the next few weeks, we’ll review this syntax again and get into the weeds with selection and serialization functions and review some of the use cases that I implement most often like interacting with date widgets, using static queries to do all sorts of cool stuff, and more!

1 comment on “SAQL as a Second Language: Interactions

  1. This helps me to understand basics..thanks Kristi.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: