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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
christielu
Frequent Visitor

DAX if statement-evaluate multiple values in one column, return single value

Hi all! I'm wondering if I could write a better IF statement for my problem. I have a "person" column, and I need to create a "location" column based on person's name. There are a lot of names (over 30) and lots of locations (10). Instead of writing endless nested IF statement below, is there an easier way to do this? 

 

Just an example of my current statement: if(OR(person_name="person1",person_name="person2"),"location1", IF(OR(person_name="person3" ...

 

Table1:

Person_Name Location

person1location1
person2location1
person3location1
person4location1
person5location1
person6location1
person7location1
person8location1
person9location1
person10location2
person11location2
person12location2
person13location2
person14location2
person15location2
person16location2
person17location2
person18location2
person19location2
person20location3
person21location3
person22location3
person23location3

Thank you in advance! 

1 ACCEPTED SOLUTION
shep123
Helper I
Helper I

depends what you mean by endless for which solution is better.

 

This one has a few nested ifs but not nearly as many:

Location =
IF ('Table'[Person_Name] IN { "person1", "person2", "person3" },
"location1", IF ( 'Table'[Person_Name] IN { "person10", "person11", "person12" },  "location2" ))
 
This one is my prefered:
Location_alt =
SWITCH (
TRUE (),
'Table'[Person_Name] IN { "person1", "person2", "person3" }, "location1",
'Table'[Person_Name] IN { "person10", "person11", "person12" }, "location2"
)
 
 
I obviously only did a subset of your data. You probably could do this cleaner doing enter data and making a relationship between the tables on person name but if you want to do a calculated column this is how I would.
 

View solution in original post

3 REPLIES 3
shep123
Helper I
Helper I

depends what you mean by endless for which solution is better.

 

This one has a few nested ifs but not nearly as many:

Location =
IF ('Table'[Person_Name] IN { "person1", "person2", "person3" },
"location1", IF ( 'Table'[Person_Name] IN { "person10", "person11", "person12" },  "location2" ))
 
This one is my prefered:
Location_alt =
SWITCH (
TRUE (),
'Table'[Person_Name] IN { "person1", "person2", "person3" }, "location1",
'Table'[Person_Name] IN { "person10", "person11", "person12" }, "location2"
)
 
 
I obviously only did a subset of your data. You probably could do this cleaner doing enter data and making a relationship between the tables on person name but if you want to do a calculated column this is how I would.
 

Hi again! I used SWITCH statement in Excel data model and it worked. But when I used the exact same statement (copy and paste) in SSAS, it gave me an error that the syntax for 'IN' is incorrect. 

I did some google search and a few people had the same issue but no solution. Do you happen to know why? Thank you!

Thank you so much! SWITCH works perfectly.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.