Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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
| Color | Color Groups -> This is is the result of the dax code above |
| Red | Primary
|
Yellow
| Primary |
Blue
| Primary |
Orange
| Secondary |
Green
| Secondary |
| Yellow Orange | Tertiary |
| Yellow Green | Tertiary |
Solved! Go to Solution.
@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
@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
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.