Print Page | Close Window

Crystal Reports 2008

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=6502
Printed Date: 02 May 2024 at 3:12pm


Topic: Crystal Reports 2008
Posted By: vpriyanka2001
Subject: Crystal Reports 2008
Date Posted: 28 May 2009 at 8:41am
Hi,
 
I need some help from crystal gurus, I am creating a crystal report using Stored Procedure.When I run stored procedure and get results for eg  for 1 field  it gets sum of (100) and when I pull this field in detail section and do a sum there I am expecting (100) but it is giving me some other value(eg 70).
 
Why are values not matching in reports and SQL SERVER



Replies:
Posted By: DBlank
Date Posted: 28 May 2009 at 9:51am
Not sure I am understanding your problem. Perhaps you can clarify.
In your SP resulting in 100 are you adding differnt colmns together to get a total of these or are you SUM multiple rows to get the 100?
Same issue in Crystal...Are you adding columns or summing rows?
If youa re summing rows and you grouped your data it may be the reason.
Also are you using the select expert in crystal that would omit data that was not being excluded in your original SP... that might account for the difference.


Posted By: vpriyanka2001
Date Posted: 28 May 2009 at 10:01am
Thanks for replying.
After digging more into the issue, I see when I am running my stored procedure in SQL Server it is giving me record count of 3500 records and when I am calling Stored procedure it is ol=nly returning 2500 records and that's what is making my total SUM go wrong as 1000 records are missing but now the question is why is crystal report not pulling all the records..


Posted By: DBlank
Date Posted: 28 May 2009 at 10:06am

So you are using the SP directly in your report, correct?

Are you joining it to anything via the DB Expert in Crystal? If so the join may be dropping records so you may need a left join.
Are you using any select statement in crystal at all? That also might explain it.


Posted By: vpriyanka2001
Date Posted: 29 May 2009 at 9:44am

I was able to fix that, thanks for all your help.

I have another issue for the same report.
I need to take out average and then summarize it.
 
I can summarize it on running totals and one time by mistake the formula above did work and gave me correct result but since I refreshed it istarted giving me error.
 
my Formula for average is:
If {UpLoad_Report_EOM;1.PolicyCount} >0 then  0 else {UpLoad_Report_EOM;1.PolicyPremium} / {UpLoad_Report_EOM;1.PolicyCount} ;
 
error is : Division by zero
 
I tried multiple formula, but same error.
 
1. If {UpLoad_Report_EOM;1.PolicyCount} >=0 Then {UpLoad_Report_EOM;1.PolicyCount} *
({UpLoad_Report_EOM;1.PolicyPremium} / {UpLoad_Report_EOM;1.PolicyCount})
 
2. If {UpLoad_Report_EOM;1.PolicyCount} < 0 Then
     0
Else
    {UpLoad_Report_EOM;1.PolicyPremium} /{UpLoad_Report_EOM;1.PolicyCount}
 
AnY Idea.


Posted By: DBlank
Date Posted: 29 May 2009 at 9:47am
If {UpLoad_Report_EOM;1.PolicyCount} = 0 then 0 else {UpLoad_Report_EOM;1.PolicyPremium} / {UpLoad_Report_EOM;1.PolicyCount}


Posted By: vpriyanka2001
Date Posted: 29 May 2009 at 9:55am
If I do = (then my result gets incorrect) if I do <0 then only it gives me correct average.


Posted By: DBlank
Date Posted: 29 May 2009 at 10:09am
Are you trying to get an average from 2 fields in one DB row or are you trying to get an average of a count of rows and a sum of another field from all of the counted rows?
If so is this for all records in the report or a sub grouping?
If a sub grouping do you have a group in your report set up that supports displaying the results?
 
 


Posted By: vpriyanka2001
Date Posted: 29 May 2009 at 10:51am
I have 2 field names as Policies Issued Count and Policies Issued Premium and I have to take out average from these 2 fields.
Basically premium / count.
 
My count has values as 0's and 1's.
 
 


Posted By: DBlank
Date Posted: 29 May 2009 at 11:29am
Originally posted by vpriyanka2001

 
My count has values as 0's and 1's.
 
 
This leads me to believe that you really need a Summary Average.
premium / count is going to be premium / 1 or premium / 0 which is not going to give you an average.
I think you are really trying to get a average as:
Sum({UpLoad_Report_EOM;1.PolicyPremium}) / Sum({UpLoad_Report_EOM;1.PolicyCount})
or at some group level
Sum({UpLoad_Report_EOM;1.PolicyPremium}, groupfieldhere) / Sum({UpLoad_Report_EOM;1.PolicyCount}, groupfieldhere)
 
Is this more on track with what you are trying to do?


Posted By: vpriyanka2001
Date Posted: 29 May 2009 at 11:40am
Thanks, It worked.
 
Thanks a lot again.


Posted By: vpriyanka2001
Date Posted: 08 Jun 2009 at 9:10am
Hi, I installed Crystal 2008 and it's again giving me DIVISION BY ZERO error for the formula below.
ANy suggestions.
 
Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.ProgramCode})
/ Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode})


Posted By: DBlank
Date Posted: 08 Jun 2009 at 11:08am
if Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}) =0 then 0 else
(Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.ProgramCode})
/ Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}))


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 8:41am
Thanks, this works.


Posted By: DBlank
Date Posted: 09 Jun 2009 at 8:45am
FYI - whenever you are using division and the field you are dividing by has the potential to be Zero (not just if it is zero right now but can ever be zero) you will want to use the the "if-then" in the division formula.
if division_field = 0 then 0 else x / division_field


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 10:38am
Thanks, will keep in mind.
 
I have another small question. I am using this as formula in my report.
My report has a group Type(New and Renew).
Formula below is helping me to get average, but I cannot use this formula to do autosum based on Type. Any idea how can I do.
 
Field I am using for Type is : {UpLoad_Report_EOM;1.PolicyType}
"New" & "Renew"
 
"if Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}) =0 then 0 else
(Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.ProgramCode})
/ Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}


Posted By: DBlank
Date Posted: 09 Jun 2009 at 11:06am
Each of these SUMS is summing at the ProgramCode group level.
Sum(x,y)
x=field to sum
y=field grouped on
If you want to do the sum at a different group level, use that group level field in the formula instead, probably will be:
 
if Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.PolicyType}) =0 then 0 else
(Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.PolicyType})
/ Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.PolicyType})
The formula must be palced on the Group header or footer that it is evaluated for ({UpLoad_Report_EOM;1.PolicyType} group footer or header) in order to get the correct results to display.


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 11:41am

I am using 2 Group Levels

1. Policy Type (New, Renew)
2. Program code (Multiple)
Columns I am using are getting Running Totals, based on Program type.
 
Formula below helped me to get the right average but on this formula I cannot do autosum .
I need sum on average based on Program code first and then Policy type.
 
Report is showing all values correct but only SUm on AVerage is giving incorrect values..
 
if Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}) =0 then 0 else
(Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.ProgramCode})
/ Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}))
.


Posted By: DBlank
Date Posted: 09 Jun 2009 at 11:44am
Sorry, not sure what you mean by SUm on Average?
 
As far as I know Crystal does not allow the summary of a summary function.
Eg. AVERAGE of a SUM or a SUM of an AVERAGE.


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 12:08pm
 Ineed Subtotal for Average in Yellow BOXES Below 
The One I am showing is for New Business, same way I need for Renew Business and Finally SUM of (Ne+Renew Subtotals)
                                                                             
                          POLICIES ISSUED     PREMIUM   ATTRITIONS  
    PRGM - CODE                         AVG                   AVG
                                                                             
NEW BUSINESS
ES 19 2 15 0 $0 0 0 1 5,251 5,251
HMS-MAIN 27 21 2 7 $6,282 897 0 3 1,039 346
REIC/RESW 22 0 0 21 $12,822 311 0 19 5,510 290
REXS 42 39 0 33 $39,953 822 0 0 0 0
RMAX 27 0 2 6 $84,136 7,364 0 1 8,441 8,441
RMAXF 3 0 0 0 $84,136 0 0 0 0 0
STD 740 382 202 111 $263,588 1,617 0 56 49,099 877
                                                                             
  Total New Business 880 444     221   178     $263,588     0     80     69,340          


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 12:11pm
Color is Missing.
Total New Business for Average is Missing.
We got this above average from the formula you gave.


Posted By: DBlank
Date Posted: 09 Jun 2009 at 12:42pm
I think I see what you want.
You have a group level that has a value of "New Business".
To get the average you need to create a new formula field that will give you the average for the group level and place the formula field in the group footer for that. This should be the same formula that gets your other percentages but replace the group level field in it with whatever the field is that you get the "New Business" result from.
 
You also may want to test out the two sums (that you are using in the division by) as seperate formulas to see if they are summing correctly. Place them on that same footer to see the values per group level.
If they are not correct are there duplicate records that need to be accounted for?
 


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 2:05pm

I think we need separate formula for sum:

Subtotal new Business (red column should have totals for all the above AVG)
Eg AVG total for these should be:(11012)
 
Average what all numbers you see above we got from the formula.
 
if Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}) =0 then 0 else
(Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.ProgramCode})
/ Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.ProgramCode}))
 
I think we need another formula that can sum these up, based on New and Renew Business.
We need to use same formula what is above with adding another group type to it as ({UpLoad_Report_EOM;1.PolicyType})
 
 
 
 
PRGM - CODE AVG
NEW BUSINESS
ES 0
HMS-MAIN 897
REIC/RESW 311
REXS 822
RMAX 7,364
RMAXF 0
STD 1,617
Sub Total New Business  
PRGM - CODE AVG
RENEW BUSINESS
ES 0
HMS-MAIN 454
REIC/RESW 775
REXS 822
RMAX 456
RMAXF 88
STD 1,617
Sub Total ReNew Business  


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 2:10pm

For Column AVerage, SUB Total New Business Should come: 11012

and Average, Sub Total Renew Business Should come: 4212


Posted By: DBlank
Date Posted: 09 Jun 2009 at 2:14pm
Yes. You cannot just sum and the program level and then average it.
Sorry I cannot just give you the formula but it is really hard to understand your table and field names and then know how you have them grouped in the report...
Based on your last commment I think it will be:
if Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.PolicyType}) =0 then 0 else
(Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.PolicyType})
/ Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.PolicyType}))
 
You can also tets each part for your amounts in seperately formulas as I suggested earlier...
Sum({UpLoad_Report_EOM;1.PolicyPremium}, {UpLoad_Report_EOM;1.PolicyType})
and
 
Sum({UpLoad_Report_EOM;1.PolicyCount},{UpLoad_Report_EOM;1.PolicyType})
 
to verify these give you the 11012 and 4212 sums you indicated above.


Posted By: vpriyanka2001
Date Posted: 09 Jun 2009 at 3:05pm
Thanks for all your help,
None of these are working, I tried these earlier too.


Posted By: vpriyanka2001
Date Posted: 10 Jun 2009 at 5:17am

Thanks, got it.




Print Page | Close Window