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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AW1976NOVA
Post Patron
Post Patron

How to use the AND function with M Code in Power Query Editor

Hi,

 

I have a pretty simple question.  Below is a custom column I'm trying to create with M Code in Power Query Editor (Transform Data).  However, I'm getting an error when I try to use the AND function.

 

Is there another way to use the AND function with M Code?  Below is my M Code with the error.  How can I incorportate the and functionality below to resolve the issue?  I highlighted the error in red below:

 

Custom Column =

 

if [Non_Emergent] + [Emergent_PC_Treatable] >.5 and [Non_Emergent] >= [Emergent_PC_Treatable] then “Non-Emergent”
else if [Non_Emergent] + [Emergent_PC_Treatable] >.5 and [Non_Emergent] < [Emergent_PC_Treatable] then “Non-Emergent-PC Treatable”
else if [ER_Needed_Not_Preventable] + [ER_Needed_Preventable_Avoidable] >.5 then “Emergent”
else if [Injury] =1 then “Injury”
else if [Alcohol] =1 then “Mental Health”
else if [Drug] =1 then “Mental Health”
else if [Psych] =1 then “Mental Health”
else ”Unclassified”

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@AW1976NOVA , and is and in power query,

 

Try like

 

if ([Non_Emergent] + [Emergent_PC_Treatable]) >.5 and [Non_Emergent] >= [Emergent_PC_Treatable] then "Non-Emergent"
else if ([Non_Emergent] + [Emergent_PC_Treatable]) >.5 and [Non_Emergent] < [Emergent_PC_Treatable] then "Non-Emergent-PC Treatable"
else if [ER_Needed_Not_Preventable] + [ER_Needed_Preventable_Avoidable] >.5 then "Emergent"
else if [Injury] =1 then "Injury"
else if [Alcohol] =1 then "Mental Health"
else if [Drug] =1 then "Mental Health"
else if [Psych] =1 then "Mental Health"
else "Unclassified"

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@AW1976NOVA , and is and in power query,

 

Try like

 

if ([Non_Emergent] + [Emergent_PC_Treatable]) >.5 and [Non_Emergent] >= [Emergent_PC_Treatable] then "Non-Emergent"
else if ([Non_Emergent] + [Emergent_PC_Treatable]) >.5 and [Non_Emergent] < [Emergent_PC_Treatable] then "Non-Emergent-PC Treatable"
else if [ER_Needed_Not_Preventable] + [ER_Needed_Preventable_Avoidable] >.5 then "Emergent"
else if [Injury] =1 then "Injury"
else if [Alcohol] =1 then "Mental Health"
else if [Drug] =1 then "Mental Health"
else if [Psych] =1 then "Mental Health"
else "Unclassified"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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