percentDiff = ( (A == 0) || (B - A == 0) ? 0 : ((B - A) / A) * 100) )

But everone has their own style.

]]>You would have the same problem if one month was 0 and the next anything. For example 0 to 10: (10-0)/0

It is because you are asking "what is the **relative** change since last month" - how do you relate to a zero month?

So, you must have an "if (A == 0) { PctDiff=0 } else { PctDiff=((B-A)/A)*100 }" kind of code. (I just made PctDiff=0, but even better would be to print out an "N/A" or something to show that you know it is not possible to calculate the %)

BTW, what language are you writing it in?

]]>[(B-A)/A]*100 is the right way of calculating the percentage increase, which you have done. Problem arises when the difference is 0 and both the values are 0. I don't think there is any mathematical solution, but if you could program in such a way that

the formula is applied only when the difference ≠ 0

and when the difference is zero, the percentage change is zero,

your problem could be solved!]]>

January = 50; February = 75

% difference between January and February = +50%

I calculate this as follows:

[(75 - 50)/50]*100

Everything works fine until get 2 consecutive months with a 0 value, example:

March = 0; April = 0

% difference between March and April:

[(0 - 0)/0]*100 => which of course is infinite and returns an error. But we all know that in fact the % difference between these 2 months is zero...unfortunately a computer doesn't understand this.

My question: is there another formula I can use to calculate the difference, that will not return an error when 2 consecutive values are zero?

Thank you very much if you can help me.]]>