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
Anonymous
Not applicable

Substraction in M language

Hello,

How can I write calculation in M query to SUBSTRACT two column values along with IF and SUM combination?

 

I know using DAX but I want to write in M language. Can you please suggest. Below is simple example which I am trying to acheive using M language

 

EX:

 

Final Formula = (if A= "Y" then sum (B) Else null) - (if C= "Y" then sum (D) Else null) 

 

Thank you

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

I'm guessing the formula will add a new colum, please remember that it's evaluated per row so there is no SUM as such
code would look like this

(if Text.Upper([A])= "Y" then [B] else 0) - (if Text.Upper([C])= "Y" then [D] else 0)

I replaced null with 0s because in M

null + 2 = null

you could add another if to replace 0 with null when necessary


I also added Text.Upper cause M is case sensitive when making comparisons

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

2 REPLIES 2
Stachu
Community Champion
Community Champion

I'm guessing the formula will add a new colum, please remember that it's evaluated per row so there is no SUM as such
code would look like this

(if Text.Upper([A])= "Y" then [B] else 0) - (if Text.Upper([C])= "Y" then [D] else 0)

I replaced null with 0s because in M

null + 2 = null

you could add another if to replace 0 with null when necessary


I also added Text.Upper cause M is case sensitive when making comparisons

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Hi @Anonymous,

 

Does that make sense? If so, kindly mark the answer as solution to close the case.


Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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.