Forum Discussion
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
Community 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.
- jb123Frequent Visitor
That worked - thanks :)