Forum Discussion
Using a Measure as a Legend in a Stacked Column Visual
- 6 months ago
Hi mdm2025
Measures can’t be used as a legend because they don’t exist per row—they only calculate in the filter context. If a chart needs a legend, it needs real, row-level values. So the fix is to materialize the measure’s result in a physical column. That way, each row has a value the chart can actually use. For example:
Sales by Grouping = VAR __TBL = ADDCOLUMNS ( SUMMARIZE ( Sales, Sales[Fruit], Sales[State] ), "@Amt", CALCULATE ( SUM ( Sales[Sales] ) ), "@Grouping", IF ( CALCULATE ( SUM ( Sales[Sales] ) ) >= [Parameter Value], "Yes", "No" ) ) VAR __FILTERED_TBL = FILTER ( __TBL, [@Grouping] IN VALUES ( 'Grouping'[Grouping] ) ) RETURN SUMX ( __FILTERED_TBL, [@Amt] )The @Grouping column in the virtual table contains the “legend” logic but to use it in a visual, it must be materialized via a disconnected table that holds the expected grouping values. The virtual table is then filtered so that @Grouping matches the values in the disconnected table, allowing the measure to behave like it has row-level categories for the legend.
Link to the sample pbix files are in the video description on YouTube - https://www.youtube.com/watch?v=dEuDlcSzk7k
Hi mdm2025 , you could also try to use Parameter option. If you go to Modeling Tab > New Parameter > Fields, you will be able to add your measurements to one Parameter. Later simply add this Parameter to the stacked bar chart to Y axis.
Kind regards,
Agata
If this post helps, then please consider to Kudos it and Accept as the solution and Kudos to help the other members find it more quickly