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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Honne2021
Helper II
Helper II

If text contains then, multiple results based on condition

Is there a shorter code for this:

SWITCH(TRUE(), ISERROR(SEARCH("RED", 'Sheet1'[Color])) <> TRUE (), "Primary",
SWITCH(TRUE(), ISERROR(SEARCH("YELLOW", 'Sheet1'[Color])) <> TRUE (), "Primary",
SWITCH(TRUE(), ISERROR(SEARCH("BLUE", 'Sheet1'[Color])) <> TRUE (), "Primary",
SWITCH(TRUE(), ISERROR(SEARCH("ORANGE", 'Sheet1'[Color])) <> TRUE (), "Secondary",
...and so on.... I was wondering if there is a shorter way of doing it

ColorColor Groups -> This is is the result of the dax code above
Red

Primary

 

Yellow

 

Primary

Blue

 

Primary

Orange

 

Secondary

Green

 

Secondary
Yellow OrangeTertiary
Yellow GreenTertiary
1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@Honne2021 how about this?
In general you only need to use the SWITCH one time
I also changed fro iserror so contatinstring:

 

 

Column = 
SWITCH(
    TRUE(),
    CONTAINSSTRING('Sheet1'[Color], "Yellow Orange") || CONTAINSSTRING('Sheet1'[Color], "Yellow Green"), "Tetriary",
    CONTAINSSTRING('Sheet1'[Color], "Red") || CONTAINSSTRING('Sheet1'[Color], "Yellow") || CONTAINSSTRING('Sheet1'[Color], "Blue"), "Primary",
    CONTAINSSTRING('Sheet1'[Color], "Green") || CONTAINSSTRING('Sheet1'[Color], "Orange"), "Secondary"
)

 


Here is a link to download a sample solution file:
If text contains then, multiple results based on condition 2022-08-02.pbix

2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

1 REPLY 1
SpartaBI
Community Champion
Community Champion

@Honne2021 how about this?
In general you only need to use the SWITCH one time
I also changed fro iserror so contatinstring:

 

 

Column = 
SWITCH(
    TRUE(),
    CONTAINSSTRING('Sheet1'[Color], "Yellow Orange") || CONTAINSSTRING('Sheet1'[Color], "Yellow Green"), "Tetriary",
    CONTAINSSTRING('Sheet1'[Color], "Red") || CONTAINSSTRING('Sheet1'[Color], "Yellow") || CONTAINSSTRING('Sheet1'[Color], "Blue"), "Primary",
    CONTAINSSTRING('Sheet1'[Color], "Green") || CONTAINSSTRING('Sheet1'[Color], "Orange"), "Secondary"
)

 


Here is a link to download a sample solution file:
If text contains then, multiple results based on condition 2022-08-02.pbix

2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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