Forum Discussion

ola7mat's avatar
ola7mat
Frequent Visitor
8 years ago
Solved

OR statements

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 false

 thanks, am quite a novice as you can imagine!

 

5 Replies

  • JoHo_BI's avatar
    JoHo_BI
    Responsive Resident

    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!

    • ola7mat's avatar
      ola7mat
      Frequent Visitor

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

      • ChrisMendoza's avatar
        ChrisMendoza
        Resident Rockstar

        ola7mat,

         

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