Forum Discussion

jb123's avatar
jb123
Frequent Visitor
9 years ago
Solved

How to create a calculated column with multiple conditions?

I need to create a column based on values in different columns.  I can easily create a rule for the column if the value in either column is true or false.   Here is what I have for the query:

 

= Table.AddColumn(#"Renamed Columns", "EDU_NP", each if [IsEDU] = true then "EDU" else if [IsNonProfit] = true then "NP" else null )

 

How do I add a rule if both values are true or false?  For example if [IsEDU] = true & if [IsNonProfit] = true then EDU/NP?

 

TIA.

  • You are close. & must be and.

     

    = Table.AddColumn(#"Renamed Columns", "EDU_NP", each if [IsEDU] = true and [IsNonProfit] = true then "EDU/NP" else if [IsEDU] = true then "EDU" else if [IsNonProfit] = true then "HP" else null)

    Remark: if all fields have true/false values (no other values or nulls), then you can omit the "= true"'s.

     

2 Replies

  • MarcelBeug's avatar
    MarcelBeug
    Icon for Community Champion rankCommunity Champion

    You are close. & must be and.

     

    = Table.AddColumn(#"Renamed Columns", "EDU_NP", each if [IsEDU] = true and [IsNonProfit] = true then "EDU/NP" else if [IsEDU] = true then "EDU" else if [IsNonProfit] = true then "HP" else null)

    Remark: if all fields have true/false values (no other values or nulls), then you can omit the "= true"'s.