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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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