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

IF string equals A, or B, or C, then D

Hi all, I am pretty new to DAX, and I have been stuck on an IF statement since this morning. 

 

The problem is I have a list of countries as strings. I want to group them, using a new column, into continents.

For instance:

IF [country] = "Italy", "Europe".

and this line works pretty well. The problem is I would like to specify also other nations. I don't want to create endless IF statements, you know. XD

 

So I think I need something like that:

IF [country] = "Italy", "Germany", "Spain", then "Europe"

Thanks for any help you can give me. Also, if there are better solutions, my ears are open 😄 💙

 

 

1 ACCEPTED SOLUTION
IEG
Frequent Visitor

You can do it with SWITCH, try this,

 

SWITCH (
[Country],
Italy, "Europe",
Germany, "Europe",
Spain, "Europe",

)

 

View solution in original post

2 REPLIES 2
IEG
Frequent Visitor

You can do it with SWITCH, try this,

 

SWITCH (
[Country],
Italy, "Europe",
Germany, "Europe",
Spain, "Europe",

)

 

Anonymous
Not applicable

Many thanks! Your solution is exactly what I was looking for. I started to write something like the code I've placed below, but it's a complete waste of time! Your solution is definitely better!

Have a lovely day,
Ernesto.

calc_continents = 

IF(

CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Austria")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Belgium")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Bulgaria")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Croatia")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Cyprus")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Czechia (Czech Republic)")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Denmark")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Estonia")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Finland")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "France")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Germany")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Greece")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Hungary")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Ireland")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Italy")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Latvia")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Lithuania")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Luxembourg")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Malta")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Netherlands")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Poland")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Portugal")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Romania")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Slovakia")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Slovenia")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Spain")

|| CONTAINSSTRING( 'pub?gid=137090910&single=true&output=csv'[country], "Sweden"),

"Europe")

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.

Top Solution Authors