on 05-19-2022 11:42 AM
Presentation variables allow dashboard developers to give viewers the power of self-service and flexibility. These variables are set by users when viewing the dashboard, and they can be referenced in several ways to create dynamic insights. Before we demonstrate three examples of how presentation variables can be used, let’s cover the basics about what they are on their own.
Presentation variables…
When a user sets a presentation variable, the value is stored in a named variable. Until that named variable is referenced somewhere in the dashboard, the user will not see any changes to their view. Let’s explore three ways to utilize presentation variables.
For more information about how to create a presentation variable, see our Documentation Guide about Presentation Variables
We can use the value of our presentation variable to update insight filters and measure properties. In this example we will update the value for a conditional formatting property.
Revenue values for each category/subcategory are displayed in an aggregated table. Our conditional formatting property displays values greater than 10,000,000 in green. Rather than using a static number, we will use the value set by our user with a presentation variable. To do this, simply update the value in the measure properties from 10,000,000 to the name of the presentation variable ($pv_GreaterThan).
In this example, we configured a presentation variable ($pv_DateFilter) to have four predefined values for the end user to select (Previous Day, Previous 30 Days, Previous 90 Days, and None). These four options will update the numeric values on an insight to display the total revenue over the selected period.
The formula below can be applied as an individual filter to the insights panel. The formula ensures that the number of days between the current date ($currentDate) and the sale date (Online_Store.OrderDetails.NewDate) meets the condition specified. If “None” is selected. All transactions will be returned.
or(
and
($pv_DateFilter = "Previous Day",
daysBetween($currentDate, Online_Store.OrderDetails.NewDate) = 1),
and
($pv_DatePeriod = "Previous 30 Days",
daysBetween($currentDate, Online_Store.OrderDetails.NewDate) < 30),
and
($pv_DatePeriod = "Previous 90 Days",
daysBetween($currentDate, Online_Store.OrderDetails.NewDate) < 90),
and
($pv_DatePeriod = "None", 1 = 1)
)
The screenshots below demonstrate the update to the insight when the presentation variable is changed from “None” to “Previous 30 Days”.
In this example, we will allow an end user to decide the grouping field for an aggregated table. Dashboard developers can make these updates very easily by editing a dashboard insight itself, but the presentation variable in this case allows an end user to make updates without edit access.
Like our previous example, we have a predefined variable list to choose from. Our insight requires us to use a case statement for our Group By field. The option the user selects will update the field that is used for grouping at runtime.
case(
$pv_GroupBy = "Category",
SALES.PRODUCTS.PROD_CATEGORY,
$pv_GroupBy = "Subcategory",
SALES.PRODUCTS.PROD_SUBCATEGORY,
$pv_GroupBy = "Product",
SALES.PRODUCTS.PROD_NAME,
$pv_GroupBy = "Quarter",
date.date.QuarterName,
string(
SALES.SALES.CALENDAR_YEAR
)
)
The screenshots below demonstrate the update to the insight when the presentation variable is changed from “Category” to “SubCategory”.
Guides – Presentation Variables
Concepts – Presentation Variables