Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Appreciate if anyone can advise if there is an easier way to write this in power query?
if [Colour] = "Red" or [Colour] = "blue" then true else false
I.e. how or can I write something like so
if [Colour] = {"Red","Blue"} then true else falsethanks, am quite a novice as you can imagine!
Solved! Go to Solution.
Hello @ola7mat,
Using https://www.powerquery.training/portfolio/replicate-power-pivots-switch-function/ as a guide:
(input) =>
let
values = {
{ "Blue", true },
{ "Red", true },
{ input, false }
},
Result = List.First ( List.Select ( values, each _{ 0 } = input ) ) { 1 }
in
ResultAdd Custom Column:
= fnSwitch ( [Colours] )
Yields the following result:
Proud to be a Super User!
The function allows you not to have to rewrite the many formula's. Define it once and call it as necessary. Possibly share some more details about the data and your desired output(s).
Proud to be a Super User!
Hello @ola7mat,
Using https://www.powerquery.training/portfolio/replicate-power-pivots-switch-function/ as a guide:
(input) =>
let
values = {
{ "Blue", true },
{ "Red", true },
{ input, false }
},
Result = List.First ( List.Select ( values, each _{ 0 } = input ) ) { 1 }
in
ResultAdd Custom Column:
= fnSwitch ( [Colours] )
Yields the following result:
Proud to be a Super User!
Thanks for this Chris and JoHo . I am after the correct way to write this in power query though.
Chris the solution does work however I have a number of formulas where i use this and so wont create lists for each one.
Do you know what the power query version of what JoHO wrote?
IF(Table[Colour] IN {"Red", "Blue"}, TRUE(), FALSE())
The function allows you not to have to rewrite the many formula's. Define it once and call it as necessary. Possibly share some more details about the data and your desired output(s).
Proud to be a Super User!
thanks for this, have finally got my head round the swtich function very useful.
appreciate the help very much!
Hi Ola,
Not too sure about Power Query, but DAX is easy enough.
2 ways, you can either use the IN keyword, or double pipes '||'.
In your example,
IF(Table[Colour] IN {"Red", "Blue"}, TRUE(), FALSE())
Or...
IF(Table[Colour] = "Red" || Table[Colour] = "Blue", TRUE(), FALSE())
Hope that helps!
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 42 | |
| 38 | |
| 33 | |
| 21 | |
| 15 |
| User | Count |
|---|---|
| 64 | |
| 59 | |
| 31 | |
| 27 | |
| 25 |