Link to home
Start Free TrialLog in
Avatar of deloptis
deloptis

asked on

How can I calculate percentage value +ve/-ve growth between 2 values when one or both are negative?

Hi,

I am trying to calculate the % increase / decrease between profit figures from previous to current year. Currently my formula is as follows:

If Sum ({@Current}) <> 0 and Sum ({@Previous}) <> 0 Then
((Sum ({@Current) - Sum ({@Previous}) / Sum ({@Previous})) * 100

It is fine if the current & previous years are both positive or if the previous year is positive and current is negative.

If however the previous year is negative then the values are correct but are incorrectly shown as +ve or -ve percentages (dependant upon current year figure)

I simply want to show a positive % if there has been an increase or a negative % if there has been a decrease, regardless of whether one or both figures are negative. So an example

Previous Year = -200
Current Year = 0

Increase = 100%

Does anyone know how to do this in Crystal?

Thanks in advance!!
SOLUTION
Avatar of mrider01
mrider01

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of aburr
aburr
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrider01
mrider01

aburr, go ahead and count the number of right ")" and left "(" parentheses.  On the second line of code there are five left parentheses "(", and there are only four right parentheses ")".   The end parenthesis after {@previous gets is the end to the set that begins right at the begining of the {@previous.
I'll label each one for you.  o=open, c=close.
([1o]([2o]Sum([3o]{@Current)[3c]-Sum([4o]{@Previous})[4c]/Sum([5o]{@Previous})[5c])[2c]*100


Avatar of deloptis

ASKER

Hi - I stripped down the formula to make it easier to read - but must have backfired on me. Actual formula as below:

If Sum ({@Current }, {orders_by_week.weekno}) <> 0 and Sum ({@Previous}, {orders_by_week.weekno}) <> 0 Then
((Sum ({@Current}, {orders_by_week.weekno}) - Sum ({@Previous}, {orders_by_week.weekno})) / Sum ({@Previous}, {orders_by_week.weekno})) * 100
"aburr, go ahead and count the number of right ")" and left "(" parentheses.  On the second line of code there are five left parentheses "(", and there are only four right parentheses ")"
-
you are right.
Nevertheless I believe my solution to the problem stands.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial