Turtle Rocket
Turtle Rocket

Reputation: 91

Power BI, IF statement with multiple OR and AND statements

I have a table and want to create a new column based on some columns in the table using multiple statements.

I want to do something like this:

NewColumn  = if( (colA>colB and colC=0)
             or (colD >colE and colF = 20)
             or colG = "blue",
             "True", "False") 

How would I code this in DAX?

Upvotes: 1

Views: 80131

Answers (2)

OscarLar
OscarLar

Reputation: 1335

In DAX you should write something like this:

test = 
IF(
    OR(
        OR(
            AND(
                [A]>[B]; 
                [C] = 0
            ); 
            AND(
                [D]>[E]; 
                [F] = 20
            )
        ); 
        [G] = "Blue"
    ); 
    "True"; 
    "False"
)

However, I do believe you'll get the same result by using something like this, though you should double check this code since I don't have your data.

New = 
SWITCH(
    TRUE();
    [A] > [B] && [C] = 0; "True";
    [D] > [E] && [F] = 20; "True";
    [G] = "Blue"; "True";
    "False"
)

Upvotes: 4

Strawberryshrub
Strawberryshrub

Reputation: 3379

This would be the correct syntax. Take care and dont write in upper case.

= if ([ColumnA] > [ColumnB] and [ColumnC] = 0) or 
     ([ColumnD] > [ColumnE] and [ColumnF] = 20) or 
     [ColumnG] = "blue" 
  then true 
  else false

enter image description here

Upvotes: 2

Related Questions