Calculating Percentage Growth Rate with Negative and Positive Numbers with DAX — Power BI | by Ramon Bello | Towards Data Science

Calculating percentage growth with A-B/ABS(B) seems to be a standard with most analysts and we often ignore the fact that the simple formula we rely on is not going to be correct in all cases.
I finished a report recently and was presenting the output to the team and a member asked me to extend the timeline on the report which then includes some negative growth periods, I casually extend the filter and to my surprise, the output was obviously wrong.
I returned to my DAX formula to see if I applied absolute ABS() to the denominator and Yes!, I did, but yet my result was still wrong which made me start thinking about how negative numbers might affect the output of our percentage growth rate computation.
I read a few articles for further clarity and this particular post from Ismael on Linkedin explaining relative growth stood out and elucidate the grey areas we often ignore when computing the percentage growth rate.
Made few more google search and I saw different methods some analyst used to solve the problem, the lazy method often involves returning BLANK() or Zero where any of the values is less than Zero. The other method is to create a return P or N (Positive or Negative) to cover up the inefficiency of our dear formula “A-B/ABS(B)”.
Excel super user forum came to the rescue after reading so many articles on how to tackle the problem. A Super User (Taher Ahmed) from the forum suggested thinking through the different scenarios and using If function to solve the problem.
Below is my final DAX query that finally handles every possible scenario that could affect percentage growth computation and solve it for anyone using DAX
Net Value - Growth Rate MoM% =VAR _PREV_MONTH =    CALCULATE ( [Net Value], DATEADD ( 'Calendar Table'[Date], -1, MONTH ) )VAR _CURR_MONTH =    CALCULATE ( [Net Value] )VAR _RESULT =    IF (        AND ( AND ( _CURR_MONTH < 0, _PREV_MONTH < 0 ), _CURR_MONTH < _PREV_MONTH ),        ( ( _CURR_MONTH - _PREV_MONTH ) / _PREV_MONTH ) * -1,        IF (            AND ( AND ( _CURR_MONTH < 0, _PREV_MONTH < 0 ), _CURR_MONTH > _PREV_MONTH ),            ( ( _CURR_MONTH - _PREV_MONTH ) / _PREV_MONTH ),            IF (                AND ( _CURR_MONTH < 0, _PREV_MONTH < 0 ),                ( ( _CURR_MONTH - _PREV_MONTH ) / _PREV_MONTH ) * -1,                IF (                    AND ( _CURR_MONTH > 0, _PREV_MONTH < 0 ),                    ( ( _CURR_MONTH - _PREV_MONTH ) / _PREV_MONTH ) * -1,                    IF (                        _PREV_MONTH < _CURR_MONTH,                        ( ( _CURR_MONTH - _PREV_MONTH ) / _PREV_MONTH ),                        IF (                            _PREV_MONTH > _CURR_MONTH,                            ( ( _CURR_MONTH - _PREV_MONTH ) / _PREV_MONTH ),                            ABS ( ( ( _CURR_MONTH - _PREV_MONTH ) / _PREV_MONTH ) )                        )                    )                )            )        )    )RETURN    _RESULT
Below is a simple explanation of the different scenario that’s expected when computing percentage growth rate and all beautifully handled with the above DAX formula (Credit to Taheer for the simple illustration)
A>0, B>0, AA>0, B>0, A>BA<0, B>0, |A|A<0, B>0, |A|>BA>0, B<0, A<|B|A>0, B<0, A>|B|A<0, B<0, |A|<|B|A<0, B<0, |A|>|B|
A>0, B>0, A
A>0, B>0, A>B
A<0, B>0, |A|
A<0, B>0, |A|>B
A>0, B<0, A<|B|
A>0, B<0, A>|B|
A<0, B<0, |A|<|B|
A<0, B<0, |A|>|B|
When next you’re computing percentage growth rate on your Power BI report using DAX, give a good thought to your formula and consider leveraging the snippet above.
Follow me on Linkedin to keep up with my stories
The snippet is here on GitHub — fork it!