21. Dynamic Charts: Field Parameters, What-if and Dynamic Top N
21.1 Field Parameters: Switch Measures
Steps in Power BI
- Modeling › New parameter › Fields.
- Name:
Metric Selector. - In Add and reorder fields, tick
[Total Sales],[Total Orders],[AOV],[Avg Delivery Time (mins)]. Drag to reorder. - Keep Add slicer to this page ticked › Create.
- Power BI creates a calculated table Metric Selector and a slicer. Build a line chart: X-axis =
'Date'[Date], Y-axis = Metric Selector (the parameter field). - Select "Avg Delivery Time (mins)" in the slicer. The chart switches measure, and its axis title changes automatically.
- Slicer settings › Selection › Single select On, so one metric is shown at a time. The new button slicer style looks like tabs.
The generated DAX (you can edit the display names in the first argument):
Metric Selector = {
("Sales (₹)", NAMEOF('_Measures'[Total Sales]), 0),
("Orders", NAMEOF('_Measures'[Total Orders]), 1),
("AOV (₹)", NAMEOF('_Measures'[AOV]), 2),
("Avg Delivery (min)", NAMEOF('_Measures'[Avg Delivery Time (mins)]), 3)
}
Field parameters ha navin aani khup upyogi feature aahe. Ekda vaparla ki SWITCH method visraal.
Ravindra Bagale's Tip
Field-parameter madhli ek common chuk mhanje including measures with different formats (₹ and %) on one axis without checking the format. Keep all measures formatted correctly in Measure tools, and use clear display names in the parameter table. Punha ekda karun bagha, mag pudhe jaa.