Forum Discussion
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
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
2 Replies
- Stachu
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- v-frfei-msft
Community Support
Hi Anonymous,
Does that make sense? If so, kindly mark the answer as solution to close the case.
Regards,
Frank