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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
garluc93
Frequent Visitor

How can I do a chart in Power BI using a measure as label?

This is the sample pbix I have done .This is the output I would obtain  

im2.png

I would obtain the number of customers for each month with the label defined in the measure m-mark = IF([sumlast3months]=3;"Gold"; IF([sumlast3months]=2;"Silver"; IF([sumlast3months]=1;"Bronze"; IF([sumlast3months]=0;"NotBuyer";BLANK())))) In the original file I have a label "New" too but it's expensive to add an other table. Do you have an idea?

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi @garluc93,

 

since you cannot have a measure as a legend, you need to create a small table with the values you need on the legend. And then create a measure like this:

m-mark2 = 
var _tmp = ADDCOLUMNS(VALUES(data2[Customer Number]);"SL3MO";[sumlast3months_v2])
var _mk = SELECTEDVALUE(Marks[Mark])
return
SWITCH(
    TRUE();
    _mk="Gold";COUNTROWS(FILTER(_tmp;[SL3MO] = 3));
    _mk="Silver";COUNTROWS(FILTER(_tmp;[SL3MO] = 2));
    _mk="Bronze";COUNTROWS(FILTER(_tmp;[SL3MO] = 1 ));
    _mk="notBuyer";COUNTROWS(FILTER(_tmp;[SL3MO] = 0 ));
    blank())

 

sample

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

View solution in original post

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

Hi @garluc93,

 

since you cannot have a measure as a legend, you need to create a small table with the values you need on the legend. And then create a measure like this:

m-mark2 = 
var _tmp = ADDCOLUMNS(VALUES(data2[Customer Number]);"SL3MO";[sumlast3months_v2])
var _mk = SELECTEDVALUE(Marks[Mark])
return
SWITCH(
    TRUE();
    _mk="Gold";COUNTROWS(FILTER(_tmp;[SL3MO] = 3));
    _mk="Silver";COUNTROWS(FILTER(_tmp;[SL3MO] = 2));
    _mk="Bronze";COUNTROWS(FILTER(_tmp;[SL3MO] = 1 ));
    _mk="notBuyer";COUNTROWS(FILTER(_tmp;[SL3MO] = 0 ));
    blank())

 

sample

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Hi @sturlaws , you're precious. Do you have an idea to see New clients as the customer numbers that buy for the first time in the month visualized? I have done a measure but I'm not sure what it does

 

 

m-New = 
VAR GROUPDATA= GROUPBY(Test;Test[Customer Number];Test[datalink];"FDT";MINX(CURRENTGROUP();Test[datalink]))
var _mk = SELECTEDVALUE(Marks[Mark])
RETURN
SWITCH(
    TRUE();
    _mk="New";COUNTROWS(FILTER(GROUPDATA;[FDT]>=FIRSTDATE(TimeIntelligence[Date])));
    blank())

 

 

 

I have added a column revenue and this measure that looks function in your switch

 

NewCustomers = 
COUNTROWS(FILTER(ADDCOLUMNS(VALUES(Test[revenue]);"PreviousRevenue";CALCULATE(COUNTROWS(Test);FILTER(ALL(TimeIntelligence);TimeIntelligence[Date]<MIN(TimeIntelligence[Date]))));[PreviousRevenue]=0))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.