Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
HeevaCh
Frequent Visitor

I can’t use measure as a chart legend to categorize the data

Hello!

I have a dataset like this:

DateClientTotal SalesSales PrevDiff SalesMRR Measure
2024/JanuaryA200 200New
2024/FebruaryA 500-200Lost
2023/JanuaryB100  New
2024/JanuaryB650 150Reactivation
2024/FebruaryB 150-150Lost
2023/DecemberE11885  New
2024/JanuaryE626511885-10670Reduction
2024/FebruaryE 1515-1215Lost
2024/MarchE6270 6970Reactivation
2024/AprilE6485069907880Expansion
2024/MayE365014850-11700Reduction

 

I have written a DAX code as a measure. The code is as follows:

 

MRR Measure = 
    if([firstD]=1,"New",
    if(and([Total Sales]>=0,[Sales Prev]=0),"Reactivation",
    if([Diff Sales]>=0,"Expansion",
    if(and([Total Sales]=0,[Sales Prev]<>0),"Lost",
    if([Diff Sales]<0 , "Reduction")))))

 

 

and the code for the Different Sales:

 

 

Diff Sales = [total sales]-[sales prev]

 

 

I want to add a bar chart based on this different sales value and the date. It gives me something like this:

HeevaCh_0-1716104255725.png

I want something like below, but because I have written a measure I can’t move it to the legend field in the chart. What should I do?

 

HeevaCh_1-1716104518133.png

 

2 REPLIES 2
xifeng_L
Super User
Super User

Hi @HeevaCh ,

 

You can try below solution.

 

#1. Create an auxiliary table to use as a legend field. Such as:

 

//New Table Expression

LegendTable = 
DATATABLE(
    "Item",STRING,
    "Index",INTEGER,
    {
        {"Measure1",1},
        {"Measure2",2},
        {"Measure3",3}
    }
)

 

#2. Create a dynamic measure that can calculate different measures based on different legend items.

 

//Measure Expression

AutoIndicator = 
VAR CurIndicator = SELECTEDVALUE('LegendTable'[Item])
RETURN
SWITCH(
    CurIndicator,
    "Measure1",[Measure1],
    "Measure2",[Measure2],
    "Measure3",[Measure3]
)

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

I'm sorry but It didn't work.
It's not what I want. I want the values in the chart to be catogorized. For example if the january had :
100 Expansion
100 New
-200 reduction
-50 Lost
It would be a bar with -50 value. and the bar would show that it was 100 new, -200 reduction and 100 expansion that resulted in -50.

Not necessarily a bar chart. Any chart that you recommend that would be appropriate. 

I hope I have explained it well 🙂

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.