Reputation: 91
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
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
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
Upvotes: 2