Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Quick Question.. Post Reply Post New Topic
Author Message
ChrisD
Newbie
Newbie


Joined: 27 Sep 2007
Location: United States
Online Status: Offline
Posts: 6
Quote ChrisD Replybullet Topic: Quick Question..
    Posted: 04 Oct 2007 at 10:57am
At the risk of getting laughed off the forums, a small problem is really giving me a headache.
 
How do you find the average of a sum? To explain..
 
Invoice Number      Value                  Line Item
1001                      $15                           1
1001                      $150                         2
                       SUM=$165
 
2001                      $25                           1
2001                      $15                           2
                       SUM=$40
 
If I were to simply average the value, I would get (15+150+25+15) / 4. Which would mean a average of 51.25.
 
However, in the case I am working on, this is bad as there are 4-5 line items per invoice. One line item in the thousands, the other 3-4 at meer dollars. So I want to sum the invoice, then average the sums of the invoices. This would yeild (165+40) / 2. For a real invoice average of 102.5.
 
How do I go about only getting the average of the sums of invoices?
 
If I need to be more clear, let me know. But please respond asap.
 
Thanks!
 
-Chris


Edited by ChrisD - 04 Oct 2007 at 10:58am
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 04 Oct 2007 at 11:24pm
I would create a running total formula that uses a global variable that increases by one for every new invoice printed. Then use a formula which divides the invoice total by the global variable.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
wattsjr
Groupie
Groupie
Avatar

Joined: 25 Jun 2007
Location: United States
Online Status: Offline
Posts: 51
Quote wattsjr Replybullet Posted: 05 Oct 2007 at 10:02pm
If your Invoice Average is at the Report level, I think that you could also insert a Report Summary on the Invoice Number using "DistinctCount" for the summary option.  Then divide the Invoice Total by the Summery Count  on Invoice Number. 
-jrw
IP IP Logged
Iago
Groupie
Groupie
Avatar

Joined: 01 Oct 2007
Location: United States
Online Status: Offline
Posts: 52
Quote Iago Replybullet Posted: 08 Oct 2007 at 11:56am
One possible workaround is to have a SQL view create the SUM() .
 
It would speedup performance by making the Database server do more of the work and reduce the number of records sent over the wire.
 
You will lose the line items, or you could perform two queries, add a subreport,  one for detail and one for the Average
 
create view vwInvoiceSums as
select Sum(Value) as Value, InvoiceNum from Invoices
Group by InvoiceNum
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.