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

Multiple if statements to check text critea in a colum then display my text

Hi,

 

Am pretty new to DAX and am really struggling with creating this formula,

 

What I need to achieve is I need to check multiple codes in a Colum and if they match the criteria then it would display the text that I need. But then if they don’t match if would check the next lot of codes. So it’s like IF OR statement in excel.

I Have a COLUM that looks like this which is called SDCC,

 

SDCC

ONL

MIP

ABZ

MXX

TDX

REK

CVG

AKL

GTW

AMM

ALG

 

In more details i would need create a measure that would match ONL, MIP, ABZ MXX then display the text that I would need but if it does not match, then go onto the next check of codes AKL, GTW, AMM, ALG then display my text.

 

below is the code that I used between two tables but I could only check one value  “REK” this is what I am struggling with…. I am not sure how to check multiple references. I bet it’s something very simple and am overthinking it maybe.

 

CONTAINS3 = IF(CONTAINS(RELATEDTABLE(Sheet1), test[CODE], "REK"),

   "CVG",

   ""

)

 

I also tried creating a new custum colum by using this

 

if [SDCC] = "ATH" and [SDCC] = "BAH" and [SDCC] = "BAK" and [SDCC] = "BEG" and [SDCC] = "BLR"
then "CVG"
else if [SDCC] = "BRU" and [SDCC] ="CAI" and [SDCC] ="DHA" and [SDCC] = "JNB"
then "LEJ"
else "Range Unknown"

Thanks in advance for the help!

1 ACCEPTED SOLUTION

Hi @Anonymous 

 

You may try to use IN Function.For example:

 

Column =
IF (
    Table1[SDCC] IN { "ATH", "BAH", "BAK", "BLR" },
    "CVG",
    IF ( Table1[SDCC] IN { "BRU", "CAI", "DHA", "JNB" }, "LEJ", "Range Unknown" )
)

Regards,

Cherie

 

Community Support Team _ Cherie Chen
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

3 REPLIES 3
Greg_Deckler
Super User
Super User

So, you can use "||" for OR criteria (&& for AND). But, I would use a SWITCH, not nested IF statements.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Do you have any examples for using SWITCH? and thank you for your response.

Hi @Anonymous 

 

You may try to use IN Function.For example:

 

Column =
IF (
    Table1[SDCC] IN { "ATH", "BAH", "BAK", "BLR" },
    "CVG",
    IF ( Table1[SDCC] IN { "BRU", "CAI", "DHA", "JNB" }, "LEJ", "Range Unknown" )
)

Regards,

Cherie

 

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

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.