cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: How to create a calculated column with multiple conditions?

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.

 

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
Highlighted
Community Champion
Community Champion

Re: How to create a calculated column with multiple conditions?

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.

 

Specializing in Power Query Formula Language (M)

View solution in original post

Highlighted
Frequent Visitor

Re: How to create a calculated column with multiple conditions?

That worked - thanks 🙂

Helpful resources

Announcements
May 2020 Community Highlights

May 2020 Community Highlights

It’s time for another PBI Community recap!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!

Top Solution Authors