Forum Discussion
Changing Measures using Field Parameters
In Power BI, you can create a dynamic measure that changes based on selected field parameters (like sales, profit, quantity) using DAX and field parameters. To achieve this, you can follow these steps:
Create Measures for Different Metrics: First, create individual measures for each metric you want to analyze, such as Total Sales, Quantity, and Cost. For example, create measures like Total Sales, Total Quantity, and Total Cost.
Create a Parameter Table: Create a parameter table in Power BI that allows users to select the metric they want to analyze. This table should have at least two columns: one for the parameter name (e.g., "Metric") and another for the values (e.g., "Total Sales," "Total Quantity," "Total Cost").
Create a Slicer for Metric Selection: Add a slicer visual to your report based on the parameter table's "Metric" column. This slicer will allow users to switch between metrics.
Create a Dynamic Measure Using SWITCH: Now, create a dynamic DAX measure that changes based on the selected metric. You can use the SWITCH function to achieve this. Here's an example DAX formula for a YoY change measure:
Selected Metric YoY Change =
VAR SelectedMetric = SELECTEDVALUE(ParameterTable[Metric])
RETURN
SWITCH (
SelectedMetric,
"Total Sales", [Total Sales YoY Change],
"Total Quantity", [Total Quantity YoY Change],
"Total Cost", [Total Cost YoY Change],
BLANK()
)
In this formula, it checks the selected metric using the SWITCH function and returns the corresponding YoY change measure. Adjust this formula for other time intelligence calculations like MoM change, QoQ change, etc., and for different metrics.
Add the Dynamic Measure to Matrix Visual: Finally, add the dynamic measure (Selected Metric YoY Change or similar) to your matrix visual. When users select a different metric using the slicer, the measure will automatically update based on their selection.
Now, users can use the slicer to switch between different metrics (sales, quantity, cost) and view their YoY changes, MoM changes, etc., in the same matrix visual.