Link to home
Start Free TrialLog in
Avatar of snowmanapril
snowmanapril

asked on

How to calculate percentage where subtotal figure/grandtotal figure

Dear All,

I use running total expert and I can get subtotal and grandtotal in perfect way.
Previously I was using insert summary as grand total , found out it is incorrect after performing a TOP 10 sort.
Now in my report, I suppress report details section, and I have shown the group name subtotal figure in group footer.
How do I display percentage of figure as well? meaning I need to do this subtotal/grandtotal.
But I wonder how to get grandtotal inside the group footer?
Have been trying hard but still cant figure out how to do it.
Avatar of wykabryan
wykabryan
Flag of United States of America image

So you are trying to figure out how to display a percentage in the group footer.  Have you tried creating a formula that takes:
if isnull(#subtotal) = true or #subtotal = 0 then 0
else
 (#grandtotal/#subtotal) *100

* you may need to switch them around, never was good at checks for division and for that matter coding out division.
Avatar of snowmanapril
snowmanapril

ASKER

I tried already
Cant display the correct data.

                      Subtotal Percentage=100

Category 1
Category 2
Sorry accidentally submit the comment
I use the formula you have suggested and place it together with grp footer.
Doesn't work :(

if isnull({#CampaignSubtotal}) = true or {#CampaignSubtotal} = 0 then 0
else
 //({#CampaignSubtotal}/{#CampaignTotal}) *100
({#CampaignSubtotal}/{#CampaignTotal}) *100


                          Subtotal           Percentage
Category1           73                   100
Catefory2           15                    17.05
.......



Total =  133
Just out of curiousity what happen if you uncomment this line ({#CampaignSubtotal}/{#CampaignTotal}) *100
what are the totals?
is the same.
stil showing 100 percentage
SOLUTION
Avatar of frodoman
frodoman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah I dun know sub report Oppss :(
New to crystal, so sorry :(
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The problem you're running into is that the running total is only incremented at the same time as the subtotal.  In your example for category 1 the total is only 73 at the time of evaluation so you're getting (73/73)*100.

You might want to try this:  ({#CampaignSubtotal}/Sum({WhateverYourField}))*100

I can't test it, but I think that may use the grand total instead of the running total - which is what you need.  Otherwise, I can talk you through subreports & shared variables but that's going to be a lot more work if you aren't familiar with them.

frodoman
Hi frodoman,

I cant use grandtotal summary as when i involve TOP 10 this criteria, the grandtotal is incorrect, thats y i use running total instead
Is there a reason why you are using a running total rather than a group with a sum or count of rows?
I refer to this http://www.crystalconsulting.ca/faq.html

3. Why are my grand total and/or summaries incorrect after performing a
group selection or Top N/Bottom N sort?

Answer: While record selection is evaluated during the first pass, group
selection is evaluated in the second pass. Because Crystal Reports creates
summaries in the first pass (therefore prior to evaluating group
selection), the summaries don't reflect the groups that have been
suppressed from the report.


To correctly summarize and/or grand total a report that has a group
selection formula, creating running totals, either using variables and the
WhilePrintingRecords function, or with the Running Total Expert (available
only with version 7 and 8).


I encounter divison by zero error when i using sub report method
I have selection criteria in Main report
{Incident.Campaign Name} <> "NULL" and
{Incident.Group Name} = "HELP" and
{Incident.Open Date & Time} In {?FDate} To {?FTDate}

Do I need to include all this in subreport as well?
What field shld be link between main and subreport?

where shld i put my subreport? at report header?



Your selection criteria for the subreport should be identical to the main report - otherwise you won't be counting the same number of records/values.  There should not be any link between the subreport - it's purpose is only to total the values so there isn't a need for a link - just place the subreport in your report header.

The division by zero may be a problem with how you're populating the variable.
Hi Frodoman,

I place it at sub report header, the grandtotal has division zero error, but when i place at subreport footer it works!
However, the total percentage of top 10 data does not = 100% (Due to rounding I guess).
So when I manually calculate is 100.01%.
Any kind of method can make the top 10 category total percentage is 100?
Thanks.
I'm certain it is due to rounding.  You could probably make it equal or at least closer to 100% simply be expanding the number of decimal places being shown so (for example) the value 20.25% might actually appear as 20.2386% -- it's up to you whether that is important or not for your specific report.

If I understood correctly, you have it working now other than the rounding, right?
Yup.
I got it workable by using subreport.
Kind of strange, if i did not use top 10, no need to use subreport i can calculate percentage based on grandtotal.