Search code examples
excelpowerbipowerquerypowerbi-desktopm

IF, OR and AND - Power BI


I want to add I conditional column which:

  • In the first and second step check only the code
  • In the thrird step should check the code and the quantity

As soon as i add the third step it seems that all rules break up. Below is my code:

= Table.AddColumn(#"Filtered Rows", "Category", each if [#"Code"] = "1" or [#"Code"] = "2" then "Step 1" else if [#"Code"] = "3" then "Step 2" else if [#"Code"] = "4" or [#"Code"] = "5" and [Quantity] >0 then "Step 3_A" else if [#"Code"] = "4" or [#"Code"] = "5" and [Quantity] <0 then "Step 3_B"

Any help?


Solution

  • You need parentheses.

    enter image description here

    = Table.AddColumn(#"Changed Type", "Custom", each if [#"Code"] = "1" or [#"Code"] = "2" then "Step 1"  else if  [#"Code"] = "3" then "Step 2"  else if ([#"Code"] = "4" and [Quantity] >0)  or ([#"Code"] = "5" and [Quantity] >0) then "Step 3_A"  else if ([#"Code"] = "4" and [Quantity] <0 ) or ([#"Code"] = "5" and [Quantity] <0) then "Step 3_B" else null)