?
Solved

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

Posted on 2011-03-07
12
Medium Priority
?
1,894 Views
Last Modified: 2012-08-14
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
Comment
Question by:cgettel
  • 5
  • 4
  • 2
11 Comments
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 1000 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 101

Expert Comment

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

mlmcc
0
 

Author Comment

by:cgettel
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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 

Author Comment

by:cgettel
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

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

Author Comment

by:cgettel
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 101

Expert Comment

by:mlmcc
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 101

Assisted Solution

by:mlmcc
mlmcc earned 1000 total points
ID: 35060935
No

Try

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

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

mlmcc
0
 

Author Comment

by:cgettel
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 101

Expert Comment

by:mlmcc
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

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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 …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

807 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