Hi Everyone,
I am running into an issue subtracting one field from another field when one field is equal to null. If there is a better way to do this please give me some insight.
I am dealing with Year to date sales & profit values on a monthly basis. The goal is to determine the monthly sales and profit figures. To do this I created a custom column to subtract the Current Month Year to Date values from the Previous Year to Date values from last month. I added some conditions to take into account subtracting positive and negative values. All of which seems to be working. However, whenever I run into a case where there is a value in the Current Month but null in Last month it doesn't calculate a value. For example, If Feb has $10 and Jan was null, the MTD value should be positive $10 but Power Query is showing the MTD as blank.
Below is the "M" code for the custom column that I made.
I did try switching null to "null" both ways did not make a difference.
If any one has any suggestions, please let me know where I went wrong.
Thank You everyone.
David
I am running into an issue subtracting one field from another field when one field is equal to null. If there is a better way to do this please give me some insight.
I am dealing with Year to date sales & profit values on a monthly basis. The goal is to determine the monthly sales and profit figures. To do this I created a custom column to subtract the Current Month Year to Date values from the Previous Year to Date values from last month. I added some conditions to take into account subtracting positive and negative values. All of which seems to be working. However, whenever I run into a case where there is a value in the Current Month but null in Last month it doesn't calculate a value. For example, If Feb has $10 and Jan was null, the MTD value should be positive $10 but Power Query is showing the MTD as blank.
Below is the "M" code for the custom column that I made.
Power Query:
try if [YTD Profit] > 0 and [PM_YTDProfit] > 0 then [YTD Profit]-[PM_YTDProfit]
else if [YTD Profit] > 0 and [PM_YTDProfit] < 0 then [YTD Profit]- Number.Abs[PM_YTDProfit]
else if [YTD Profit] < 0 and [PM_YTDProfit] > 0 then [YTD Profit]+ [PM_YTDProfit]
else if [PM_YTDProfit] = "null" then [YTD Profit]
else [YTD Profit] - [PM_YTDProfit]
otherwise [YTD Profit]-[PM_YTDProfit]
I did try switching null to "null" both ways did not make a difference.
If any one has any suggestions, please let me know where I went wrong.
Thank You everyone.
David