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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors