Forum Discussion

mdm2025's avatar
mdm2025
Helper I
6 months ago
Solved

Using a Measure as a Legend in a Stacked Column Visual

Hello everyone,   I’m looking for some guidance on creating a stacked column visual where the Legend is driven by a calculated measure. My goal is to have: An actual data column on the X‑axis ...
  • danextian's avatar
    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