Solved

# Positive and Negative Values in One Field - Using Formulas to Separate - Count and Avg Incorrect

Posted on 2011-03-07
1,700 Views
My database has a field called INVOICE.MERCH that has both positive (sales) data and negative (refunds) data.  I'm trying to sum, count and average both types of data.

@NegAmtRefunds
if {INVOICE.MERCH} < 0 then {INVOICE.MERCH} else 0

@PosAmtSales
if {INVOICE.MERCH} > 0 then {INVOICE.MERCH} else 0

Throwing the 0's in either part of the data (positive or negative) skews the counts and averages.

Is there a way to handle this without substituting the 0 for the values I don't want in either formula?
0
Question by:cgettel
• 5
• 4
• 2

LVL 18

Accepted Solution

UnifiedIS earned 250 total points
ID: 35060363
Setup 2 more formulas for the counts where you set the value to 1 or 0

@NegAmtRefunds_Count
if {INVOICE.MERCH} < 0 then 1 else 0

@PosAmtSales_Count
if {INVOICE.MERCH} > 0 then 1 else 0

Sum these for your count and use with your totals to get averages.
0

LVL 100

Expert Comment

ID: 35060391
Another way would be to use a running total which executes when your 0 comparison is true.

mlmcc
0

Author Comment

ID: 35060445
And then would I do a third set of formulas to get the averages?

@NegAmtRefunds_Avg
sum @NegAmtRefunds  / count @NegAmtRefunds_Count

@PosAmtSales_Avg
sum @PosAmtRefunds  / count @PosAmtRefunds_Count
0

Author Comment

ID: 35060480
mlmcc:

Do you mean that a count on the running total will count only the times when the value was NOT replaced by 0 (when the comparison yields true)?
0

LVL 18

Expert Comment

ID: 35060811
Yes, a third set for the averages using the sum and counts
0

Author Comment

ID: 35060855
UnifiedIS:

Is this the proper language for the last set?  I think

@NegAmtRefunds_Avg
sum @NegAmtRefunds  / count @NegAmtRefunds_Count

@PosAmtSales_Avg
sum @PosAmtRefunds  / count @PosAmtRefunds_Count

When I try it, I get the error, "The remaining text does not appear to be part of the formula" with everything except sum highlighted.
0

LVL 100

Expert Comment

ID: 35060866
Yes.  If you setup the ruinning total to be an average then use the evaluate when as
{INVOICE.MERCH} < 0 for the average refunds and {INVOICE.MERCH} > 0 for sales
it should calculate what you want.

mlmcc
0

LVL 100

Assisted Solution

mlmcc earned 250 total points
ID: 35060935
No

Try

sum ({@NegAmtRefunds})  / sum({@NegAmtRefunds_Count})

sum ({@PosAmtRefunds})  / sum({@PosAmtRefunds_Count})

mlmcc
0

Author Comment

ID: 35061419
mlmcc:

I wanted to accept both solutions and give points to you and UnifiedIS, but I did something wrong.  I didn't even see the option to assign points this time.

Can you reopen the question and tell me how to close properly so you and UnifiedIS can both earn points?  Sorry for the trouble.
0

LVL 100

Expert Comment

ID: 35061548
I could reopen the question but the proprieties of the situation require me to have you click the REQUEST ATTENTION link in the question and ask the EE moderators to reopen this so you can reclose.

When you reclose click the ACCEPT MULTIPLE COMMENTS link in the one you want as the solution then follow the directions.

There is no need to reopen just to redistribute the points.  You are free to do so if you want.

mlmcc
0

Author Closing Comment

ID: 35083849
Thanks to both UnifiedIS and mlmcc. I appreciate your assistance.
0

## Featured Post

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…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

#### Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!