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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors