?
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,843 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
12 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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 …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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