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
Anonymous
Not applicable

How to get if else for a text field in Measure

HI I have a table with column as Color as below:

Color

 

Red
Green
Yellow
Pink

What I need is to create a measure like this:

Color    Measure
Red       1
green    2
Yellow   3
Pink       4

I hope this is simple and can be easily done, I am trying if else but unable to get the result.

Thanks

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous,

 

You can create a measure with If() function or Switch() function, see: 

 

Measure(IF) = IF(MAX('Table3'[Color])="Red",1,IF(MAX('Table3'[Color])="green",2,IF(MAX('Table3'[Color])="Yellow",3,IF(MAX('Table3'[Color])="Pink",4,BLANK()))))

 

Measure(Switch) = SWITCH(TRUE(),MAX('Table3'[Color])="Red",1,MAX('Table3'[Color])="green",2,MAX('Table3'[Color])="Yellow",3,MAX('Table3'[Color])="Pink",4,BLANK())

 

q1.PNG

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous,

 

You can create a measure with If() function or Switch() function, see: 

 

Measure(IF) = IF(MAX('Table3'[Color])="Red",1,IF(MAX('Table3'[Color])="green",2,IF(MAX('Table3'[Color])="Yellow",3,IF(MAX('Table3'[Color])="Pink",4,BLANK()))))

 

Measure(Switch) = SWITCH(TRUE(),MAX('Table3'[Color])="Red",1,MAX('Table3'[Color])="green",2,MAX('Table3'[Color])="Yellow",3,MAX('Table3'[Color])="Pink",4,BLANK())

 

q1.PNG

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, i´m new with P.BI, i used your formula for my problem and it worked, but i don´t understand why you use MAX with text values, ¿Could you explain it?

 

thanks!

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.