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.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
88 | |
63 |