Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
aliciab425
Regular Visitor

Power Query IF and AND Statement with Multiple Conditions

Good evening,

 

I am still new to Power Query and haven’t created many custom formulas. Below is an Excel formula I need assistance recreating in Power Query.

 

  1. This formula is used to determine the comp territory

 

=IF(AND(P3="BLANK1",Q3="BLANK2",R3="BLANK3"),"Investigate",IF(AND(P3=Q3,P3=R3),P3,IF(AND(P3<>"BLANK1",Q3="BLANK2",R3="BLANK3"),P3,IF(AND(P3=R3,Q3="BLANK2"),P3,IF(AND(P3<>R3,P3<>"BLANK1",R3<>"BLANK3",Q3="BLANK2"),"300-Corporate",IF(AND(P3<>"BLANK1",Q3<>"BLANK2",P3<>Q3,R3="BLANK3"),"300-Corporate",IF(AND(P3="BLANK1",Q3<>"BLANK2",R3="BLANK3"),Q3,IF(AND(P3="BLANK1",Q3<>"BLANK2",Q3<>R3),"300-Corporate",IF(AND(P3="BLANK1",Q3="BLANK2",R3<>"BLANK3"),R3,IF(AND(P3<>"BLANK1",Q3<>"BLANK2",R3<>"BLANK3",P3<>Q3,Q3<>R3),"300-Corporate",IF(AND(P3="BLANK1",Q3=R3),Q3,IF(AND(P3=Q3,R3="BLANK3"),P3,IF(AND(P3=Q3,P3<>R3,R3<>"BLANK3"),"300-Corporate",IF(AND(P3<>"BLANK1",P3<>Q3,Q3=R3),"300-Corporate","ERROR"))))))))))))))

 

aliciab425_0-1642474214965.png

 

 

Thank you in advance for your assistance.   

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @aliciab425 ,

 

I'm not going to completely rewrite the formula, but here is the structure and terminology you need to do this in Power Query:

if [AST Terr 1] = "BLANK1" and [AST Terr 2] = "BLANK2" and [AST Terr 3] = "BLANK3" then "investigate"
else if [AST Terr 1] = [AST Terr 2] and [AST Terr 1] = [AST Terr 3] then [AST Terr 1]
else if [AST Terr 1] <> "BLANK1" and [AST Terr 2] = "BLANK2" and [AST Terr 3] = "BLANK3" then [AST Terr 1]
else if...
...
else //your escape value here e.g. null, "ERROR" etc.

 

Any logical operators (+, *, <, > etc.) can be used in exactly the same way as in Excel.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
AnkitKukreja
Super User
Super User

Hi! @aliciab425 

 

It would be easy to write the formula if you can share the sample data and expected result.

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904
BA_Pete
Super User
Super User

Hi @aliciab425 ,

 

I'm not going to completely rewrite the formula, but here is the structure and terminology you need to do this in Power Query:

if [AST Terr 1] = "BLANK1" and [AST Terr 2] = "BLANK2" and [AST Terr 3] = "BLANK3" then "investigate"
else if [AST Terr 1] = [AST Terr 2] and [AST Terr 1] = [AST Terr 3] then [AST Terr 1]
else if [AST Terr 1] <> "BLANK1" and [AST Terr 2] = "BLANK2" and [AST Terr 3] = "BLANK3" then [AST Terr 1]
else if...
...
else //your escape value here e.g. null, "ERROR" etc.

 

Any logical operators (+, *, <, > etc.) can be used in exactly the same way as in Excel.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.