Skip to main content
All CollectionsBest Practice
Building A chart with Dynamic Measure
Building A chart with Dynamic Measure
Astrato Support avatar
Written by Astrato Support
Updated over 2 weeks ago

Introduction

The document will show how to create a chart that allows end-users to change the measure displayed in the chart.



Building the measures

Create the two base measures:

  • Sales Amount- showing the total sales amount
    ​

  • Total Quantity- the total quantity sold
    ​

  • Create a measure with only a parameter.

  • Create a conditional measure.

    With a formula similar to the formula in the image below.

Building the chart

  • Create a new numeric variable - measureSwitch set the default value to one.

  • Create a string variable and name it selected measure.

    Default value: Sales Amount

  • Create a chart with the selected dimension and the measure created (Chart measure)
    In the measure properties, it's important to connect the variable created in the previous (measureSwitch) step to the parameter in the measure.

    And the "selected measure" variable to the measure custom label.
    See the highlighted section in the image below
    ​
    ​

  • Add a dropdown control to the screen from the left panel.

  • Select the "selected measure" variable and define the options for the input they appear in the image below
    ​

  • Place the control near the chart title or in another meaningful place
    and create a group containing the chart and the input form.
    The image below is one example.

Defining the actions

  • Open the Actions dialog

  • Drag the event: variable change to the canvas

  • Select the variable selected measure
    ​

  • Add an IF..ELSE action block from the conditions section.
    ​

  • Define the conditions as they appear in the image below.

    The action follows this logic:

    When the user selects an option from the dropdown menu,
    We change the variable value that determines the measure used in the chart measure.

Testing the chart

Click on the preview button and test the chart by selecting different options from the dropdown options.
The result should be similar to the image below.


​

Known Limitations

  • Only two options are supported.

  • The measure can be used in multiple charts, all of them will be impacted from the a change to variable

Did this answer your question?