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 - OR - If and Contains Statement Help Please

Hello,

Fairly new to Power BI so excuse any lack in terminology or decorum.

I have a data set that has a column where the values contain (example) ...."-WP"....

I created a new column named contains WP and put the following as the function...

 

= If(ISERROR(SEARCH("-WP",'TABLE_NAME'[COLUMN_IN_TABLE])),"No","Yes")

This worked like a charm for what I was trying to do.

 

 
I am now trying to do something very similar but now I need to say if contains ..."-D01"... or ..."-D02"... all the way out to ..."-D17"...
Trying to figure out a multiple If contains statement but am having a hard time getting it right.
 
Anyone have any suggestions?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Just to wrap this up and call this solved, here is what I did...

 

= CONTAINSSTRING('MY_TABLE'[MY_COLUMN],"AK??-D*")

 

This gave me the True/False values I needed in the new column. 

View solution in original post

3 REPLIES 3
Nathaniel_C
Super User
Super User

Hi @Anonymous ,

Try SWITCH(
          TRUE(),
          [MyMeasure]<1,expr1,
          [MyMeasure]<2,expr2,
          [MyMeasure]<3,expr3,
         …)
Works great for a lot of values such as you have, or you can make a {list} and use IN ---'Product'[Color] IN { "Red", "Blue", "Black" }

Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Nathaniel,

Thanks for the help but I am afraid I am going to need a little extra. I have not worked with SWITCH function very much and am sorry to say I am not grasping it.

 

Here is an example of what I tried to do to solve my problem, unfortunately it did not work... 

= If(Or(Left('MY_TABLE'[MY_COLUMN],6)="AK31-D",TRUE()),
If(Or(Left('MY_TABLE'[MY_COLUMN],6)="AK32-D",TRUE()),
If(Left('MY_TABLE'[MY_COLUMN],6)="AK33-D",TRUE(),FALSE())))

 

An example of the data in the column would be "AK31-D01-*****-****"

I need to be able to apply a return value of either Yes/No or TRUE/FALSE if anywhere in the string exists -D01 or D-02 or D-03 etc... up to and including -D17.

 

I feel like I somewhat understand the concept of SWITCH but, I am not quite understanding the <1 <2 etc part of it.

Anonymous
Not applicable

Just to wrap this up and call this solved, here is what I did...

 

= CONTAINSSTRING('MY_TABLE'[MY_COLUMN],"AK??-D*")

 

This gave me the True/False values I needed in the new column. 

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