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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jereaallikko
Helper III
Helper III

DAX with Multiple IF Contains Statements

Hi all,

 

I am trying to figure out a simple DAX with multiple conditions:

 

If [Column] contains "This1" then "That1" elseif [Column] contains "This2" then "That2" elseif [Column] contains "This3" then "That3" else null

 

I know that this could easily be done with conditional or custom column, but for now I need to do it with DAX. Any suggestions How this could be done?

 

BR,

Jere

7 REPLIES 7
jereaallikko
Helper III
Helper III

Hi @VahidDM & @Tanushree_Kapse 

 

What I meant, is that "This1" is included in the column. For instance, if a column value is "This1is", DAX will return "That1". Similarly, if the value is "This1isnot" it will still return "That1", because the value CONTAINS "This1"

That is what I meant with CONTAINS, not equals (=).

 

Any suggestions?

@jereaallikko 

Can you share a sample of your table after removing sensitive data here?

 

Appreciate your Kudo!!

Hi @VahidDM 

 

The table looks similar to this: 

 

DAX_CONTAINS.PNGThe "Country" Column is the one that I am trying to build with DAX. So when [Name] CONTAINS "FIN", it returns "Finland". Same goes with "GER", "Germany" & "RUS", "Russia". 

@jereaallikko 

 

Try this measure :

Country =
VAR _A =
    MAX ( 'Table'[Name] )
RETURN
    IF (
        LEFT ( _A, 3 ) = "FIN",
        "Finland",
        IF (
            LEFT ( _A, 3 ) = "GER",
            "Germany",
            IF ( LEFT ( _A, 3 ) = "RUS", "Russia", BLANK () )
        )
    )

 

Output:

VahidDM_0-1631094133608.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos✌️!!

 

This worked well! Thanks a lot.

 

Is there a way to apply similar solution to DAX column? This works in a DAX measure but if I want to use this as a slicer, it must be as a DAX column since DAX measures cannot be used as a slicer.

VahidDM
Super User
Super User

Hi @jereaallikko 

Try this measure with IF:

Measure =
IF (
    [Column] = "This1",
    "That1",
    IF ( [Column] = "This2", "That2", IF ( [Column] = "This3", "That3", BLANK () ) )
)

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos✌️!!

 

Tanushree_Kapse
Impactful Individual
Impactful Individual

Hi @jereaallikko ,

 

Try this DAX:
Measure= IF([Column]="This1","That",IF([Column]="This2","That2",IF([Column]="This3","That3")), BLANK())

 

Mark this as a solution, if I answered your question.

Kudos are always appreciated.

 

Thanks!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.