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
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
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