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

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?
cgettelAsked:
Who is Participating?
 
UnifiedISConnect With a Mentor Commented:
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
 
mlmccCommented:
Another way would be to use a running total which executes when your 0 comparison is true.

mlmcc
0
 
cgettelAuthor Commented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
cgettelAuthor Commented:
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
 
UnifiedISCommented:
Yes, a third set for the averages using the sum and counts
0
 
cgettelAuthor Commented:
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
 
mlmccCommented:
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
 
mlmccConnect With a Mentor Commented:
No

Try

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

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

mlmcc
0
 
cgettelAuthor Commented:
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
 
mlmccCommented:
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
 
cgettelAuthor Commented:
Thanks to both UnifiedIS and mlmcc. I appreciate your assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.