Solved

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

Posted on 2011-03-07
12
1,773 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
12 Comments
 
LVL 18

Accepted Solution

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

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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 100

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 100

Assisted Solution

by:mlmcc
mlmcc earned 250 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 100

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

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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