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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

HELP nested IFS WITH OR

How to do this in DAX?


IF CONTAINS([IDNUMBER],'DMM') OR CONTAINS([IDNUMBER],'NSK')
THEN 'Middle East and Africa'
ELSEIF CONTAINS([IDNUMBER],'APA')
THEN 'Asia Pacific'
ELSEIF CONTAINS([IDNUMBER],'EU')
THEN 'Europe'
ELSEIF CONTAINS([IDNUMBER],'LA')
THEN 'Latin America'
ELSEIF CONTAINS([IDNUMBER],'MEA')
THEN 'Middle East and Africa'
ELSEIF CONTAINS([IDNUMBER],'NA')
THEN 'North America'
END

 

1 ACCEPTED SOLUTION

@Anonymous 

This sort of job is ideally done in Power Query as suggested by @CNENFRNL but if you need a DAX solution and then create a table with all the codes and regions as follows

Fowmy_0-1626032597674.png

Then add the Calculated Column:

Order Region = 
var __code = LEFT([ORDER_NUMBER],SEARCH("-",[ORDER_NUMBER])-1 ) 
return
    LOOKUPVALUE( Regions[Region] , Regions[Code] , __code)

Fowmy_1-1626032640336.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @Anonymous,

If you are handling some specific replacement with column values, you can write a formula based on the switch function to check the different cases of values shared above.
If you need to handle a large number of replacements, I'd like to suggest you create a mapping table with mapping values and replace values, then you can use a simple formula to lookup the mapping table and return results.

Regards,

Xiaoxin Sheng

CNENFRNL
Community Champion
Community Champion

Why not use PQ?

let
    Lookup = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvH1VdJR8s1MSclJVXBNLC5RSMxLUXBMK8pMTlSK1YlW8gv2xq/AMcARqMCxODNRISAxOTMtMxks7BoKFHUtLcovSAXzfUCqfBJLMvMUHHNT4bp9XR0J2A+S98svKslA6IsFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Region = _t]),
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcxBCoAgEEDRu7huQDNwbRZRqYhTCIn3v0akMLl7i8/PmRkrIeDIypDZ4hzsxpBDeshCqWqPJzVeg+ATUbYLbgmk4p1F576R1W7VwEVrrKb5l8zWk1eH5Hj/xhCbLwshHqyUFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ORDER_NUMBER = _t]),

    Matchup = let code = Lookup[Code], region = Lookup[Region] in Table.AddColumn(Source, "Region", each try region{List.PositionOf(code, Text.BeforeDelimiter([ORDER_NUMBER], "-"))} otherwise "XXXXXX")
in
    Matchup

Screenshot 2021-07-11 202906.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Fowmy
Super User
Super User

@Anonymous 

SWITCH (
    TRUE (),
    [IDNUMBER] IN {"DMM", "NSK"}, "Middle East and Africa",
    
    include each line 
)




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Laedays_0-1626019671350.png

 

It's not working. It's just showing blank sir.

 

Laedays_1-1626019687104.png

@Fowmy 

@Anonymous 

 

 

Can you show me some order numbers

SWITCH (
    TRUE (),
     NOT(ISEMPTY(FILTER( {"DMM", "NSK"}, CONTAINSSTRING([Value],[IDNUMBER])))), "Middle East and Africa"
    include each line 
)

?

You can try this approach if you are searching within the text:

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

ORDER_NUMBER
CL3-PS2
DMM-ICC
DMM-PWZ
DMM-177
NSK-ICC
NA-104
NA-132
SGW-370
SGW-371
SGW-372
SGW-373
MEA-011
LA-ICC
SGW-BLN
SGW-EMS
SGW-RUS
SGW-SPR
STL-PRJ

 

@Fowmy 

Anonymous
Not applicable

here is the example ^^ @Fowmy 

@Anonymous 

This sort of job is ideally done in Power Query as suggested by @CNENFRNL but if you need a DAX solution and then create a table with all the codes and regions as follows

Fowmy_0-1626032597674.png

Then add the Calculated Column:

Order Region = 
var __code = LEFT([ORDER_NUMBER],SEARCH("-",[ORDER_NUMBER])-1 ) 
return
    LOOKUPVALUE( Regions[Region] , Regions[Code] , __code)

Fowmy_1-1626032640336.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors