Solved

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

Posted on 2008-06-25
6
1,881 Views
Last Modified: 2013-11-15
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!!
0
Comment
Question by:deloptis
6 Comments
 
LVL 2

Assisted Solution

by:mrider01
mrider01 earned 25 total points
Comment Utility
It looks like you might have an error with your order of operations.
You need to group together your (current - previous), so your end equation should be:
[ (current - previous) / previous ] * 100
whereas it looks like you currently have
(current - previous / previous) * 100.

Maybe this is just a mistake when you brought your code over here.

But also think about how you'd measure growth of a negative number.  If you start off with -10 and end up with -5, did the value actually shrink by 50% even though it got bigger?  Mathematically, yes.  This is beacue your base value is negative.  A lot of times math looks wrong and doesn't make any sense.  But when it comes time to apply it, and use it, these tricky situations make sense.
0
 
LVL 27

Accepted Solution

by:
aburr earned 50 total points
Comment Utility
I think that mrider01 has overlooked one pair of your () so your equation is as he says it should be. You can get out of your difficulty if you use the absolute value of your denominator.

I am not familiar with crystal so I do not know what the Sum function is but I think my solution will solve your problem.
I think that you do not meed to test that current is not zero

There is another difficulty when "previous" is very small. It is doubtful that under that condition the percentage means much. If previously you just broke even and you made a small change in your letterhead and the profit increased by one pound, your printer would want a big bonus because he had increased your profit by 1324%.
0
 
LVL 2

Expert Comment

by:mrider01
Comment Utility
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


0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:deloptis
Comment Utility
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
0
 
LVL 27

Expert Comment

by:aburr
Comment Utility
"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.
0
 
LVL 34

Assisted Solution

by:James0628
James0628 earned 50 total points
Comment Utility
If you just want to make sure that the % is positive if the total goes up and negative if it goes down, try something like:

If Sum ({@Previous}, {orders_by_week.weekno}) <> 0 Then
  If Sum ({@Current }, {orders_by_week.weekno}) >=
   Sum ({@Previous}, {orders_by_week.weekno}) Then
//  Force the result to be positive
    Abs ((Sum ({@Current}, {orders_by_week.weekno}) -
     Sum ({@Previous}, {orders_by_week.weekno})) /
     Sum ({@Previous}, {orders_by_week.weekno}) * 100)
  Else
//  Force the result to be negative
    0 - Abs ((Sum ({@Current}, {orders_by_week.weekno}) -
     Sum ({@Previous}, {orders_by_week.weekno})) /
     Sum ({@Previous}, {orders_by_week.weekno}) * 100)


 Note that, as aburr mentioned, you shouldn't check for current <> 0.  If you do, your example where previous is -200 and current is 0 will produce 0, instead of 100.

 James
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
I recently went through setting up a JasperReports Server using the AWS EC2 instance, and this article will cover some basic administration tasks I had to perform.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now