# Use a Global Variable in a Calculated Measure

Beginner
10 min.
Create a global variable and use it in a calculated measure
You will learn
• How to use a slider widget
• How to use a filter line widget
• How to create a global variable
• How to use a global variable in a calculated measure
Fabien AubertApril 19, 2022
Created by
April 19, 2022
Contributors
• Step 1

You can add a filter line widget in an application to apply a filter on a dimension. In this example you will filter a bar chart on the “Product” dimension by using a filter line. Select the “+” symbol in the menu bar and select the filter line widget.

In the builder panel select “Chart_1” as the source widget and “Product” as the dimension selection.

• Step 2

Then, set the minimum value to 0 and the maximum value to 1.

• Step 3

Next, add a global variable called `Discount_Percent` with the type Number and the default value equal to 0.

• Step 4

From the original sales price for a product, we want to calculate the discount price. To do that, create a calculated measure called `Discount Price` with the following formula.

As you can see we retrieve the value of the global variable `Discount_Percent` in the formula. The value is defined by the slider selection.

• Step 5

Now, save our changes and run the application. Select 0.5 in the slider and “pomegranate and apple cider” in the filter line. You can see that the Discount Price is half of the Original Sales Price.

• Step 6