Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
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
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.