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
I have not clearly understood what you want to achieve as there is no legend in the image you provided. Can you please provide more insights into what you are trying to get? We might have a solution using a measure as a filter but the complexity is high so we need to be sure we understood what you need. Also, providing the pbix would be good so we immediately apply the fix in pratice to check the outcome vs what you need. You can share via private message or here with a link to a cloud service of some kind (if for privacy both are not an option please considuer giving us some data we can import in power bi to replicate the thing)
Thanks
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Hi FBergamaschi ,
I basically want to add a measure in the below field of a stacked column chart which is against PowerBI default design so I am asking if there is another way to have a stacked column broken down by a measure within a visual.
Thank you,
Marius