Calculating Sub-totals as a percentage of Grand-total in Crystal Reports 2008

人盡茶涼 提交于 2019-12-25 04:41:31

问题


I know this has been asked time and again by people all over the net, but I can't for the life of me figure out why my solution isn't working.

I have a bunch of groups, and in each group's footer I have a running total which acts as a sub-total for that group. At the very bottom of the page, I have a running total which adds all these sub-totals together to give a grand-total. This all works great.

To the right of each sub-total (group footer), I have a formula field which calculates what proportion of the grand-total this sub-total represents.
i.e. if the Grand-total is 4, and the sub-total is 1, the formula field displays 25%.

The problem is that for each group in the report, the Grand-total hasn't yet been fully counted (until the last group), and so the percentages are being calculated against incomplete Grand-totals.

To combat this, I've tried using the WhilePrintingRecords; function on my percentage formula fields to ensure that the sub-total percentages are not calculated until the 2nd pass of the report, by which time the Grand-total should be fully calculated.

WhilePrintingRecords;
If {@LoggedToday} > 0 Then
    {#LoggedToday}  / {#TotalLoggedToday} * 100
Else
    0

It's not working though! It's literally had no impact what-so-ever :o(

Does anyone have any idea where I'm going wrong here?
Thanks.


回答1:


Yes, you're using a running total to calculate a grand total.

Instead, I suggest creating a Crystal formula for your percentage, in the form:

Sum ({ numeric field }, { grouping item }) % Sum ({ numeric field })



来源:https://stackoverflow.com/questions/4205573/calculating-sub-totals-as-a-percentage-of-grand-total-in-crystal-reports-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!