Forum Discussion
Vary the calculated column formula
- 1 year ago
Hi markperrone ,
You should use a matrix visual instead of calculated columns because calculated columns are static and do not respond to slicer selections. To show metrics like Top 20 suppliers, Gross revenue, and Shipments across two selected months and YTD, start by reshaping your data into a long format with columns for Metric, Date, and Value. Then, create a single DAX measure:
Metric Value = SUM('MetricsTable'[Value])In the Date table, create a calculated column that assigns labels like "Month1", "Month2", and "YTD" based on user selections:
Selected Label = SWITCH(TRUE(), 'Date'[Month] = SELECTEDVALUE('MonthSelector'[Month1]), "Month1", 'Date'[Month] = SELECTEDVALUE('MonthSelector'[Month2]), "Month2", 'Date'[Date] IN DATESYTD('Date'[Date]), "YTD" )Use this new label as the column field in the matrix. Put Metric on the rows, the Selected Label on the columns, and Metric Value as the values. This setup keeps your model dynamic and responsive to slicers. Do not use SWITCH inside a calculated column to try and change metrics—it won’t work because calculated columns are evaluated during data load, not when slicers change. Measures and matrix visuals are designed to handle exactly this kind of flexible layout.
Best regards,
Hi @markperrone ,
Just wanted to check if you had the opportunity to review the suggestion provided?
If the response has addressed your query, please accept it as a solution so other members can easily find it.
Thank You