Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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
Solved! Go to Solution.
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
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
Hi @Anonymous,
Does that make sense? If so, kindly mark the answer as solution to close the case.
Regards,
Frank
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!