Reusing variables across datasets
How to access Domo's "global" variable functionality
Variables are controls that allow for more complex filtering on Domo content. They are initially created on a specific dataset, but once a variable is set up, we often want to offer the same filter selections on other content. Domo describes variables as "global," meaning one variable can be used across different datasets, cards and dashboards. However, a variable created on one dataset doesn't automatically show up on other datasets. In this article, I'm going to cover how to add an existing variable to a new dataset and control cards from both datasets with one variable control.
How variables work behind the scenes
A variable is (generally) a static list of values that viewers pick from via a control card. On its own, a variable cannot change anything in a card or dashboard. However, you can use variables in Beast Mode calculations for more flexible content filtering and display. When a viewer selects a value on a variable control, Domo passes that value into every Beast Mode that references the variable, and the cards using those Beast Modes update accordingly. Because of this, cards on a new dataset can only respond to a variable once a Beast Mode on that dataset references it.
Adding an existing variable to a new dataset
When writing Beast Mode calculations, Domo auto-suggests the names of fields and variables as you type. If a variable has already been used on a dataset, it appears in the suggested list. However, if it has not been used on the dataset, it will not be suggested. That may lead to the assumption that variables cannot be reused across datasets, which is not true. Since the variable already exists, we don't need to create it again. Instead, we reference it by name in a Beast Mode on the new dataset.
- Open a card built on the new dataset in Analyzer and create a Beast Mode. (This can also be done in the Beast Mode Manager.)
- Type the variable's name in backticks, matching the spelling and case exactly. (For example,
reportingPeriod.) - Finish the calculation and save the Beast Mode.
Once the Beast Mode is saved, the variable will start showing up in the Variables tab on that dataset's cards. From there, it works the same way it does on the original dataset. Here's an example of a Beast Mode that references a Reporting Period variable created on a different dataset:
CASE
WHEN `reportingPeriod` = 'Year to Date'
AND YEAR(`Ship Date`) = YEAR(CURDATE())
AND `Ship Date` <= CURDATE() THEN 1
ELSE 0
END
Controlling cards from different datasets
On an app or dashboard, a variable control changes every Beast Mode that references it, regardless of which dataset the Beast Mode is built on. For example, one Reporting Period control can update a sales card and a shipping card at the same time, even though each card uses a different dataset. Since each variable can only be added to a dashboard once, a single control is all the dashboard needs.
For more information about variables, see Domo's public documentation: Variables | Overview