简体   繁体   English

Crystal报表中的条件运行总计

[英]Conditional Running Total in Crystal Reports

Using VS 2008 Crystal Reports, I would like to do a running total on a formula that is calculated on a group change. 使用VS 2008 Crystal Reports,我希望对根据组更改计算的公式进行总计。 When I click on add a running total, this formula does not appear in the Available Tables and Fields list. 当我单击添加运行总计时,此公式不会出现在“可用表和字段”列表中。

This is the logic: 这是逻辑:

On Change Group of group 关于组的变更组

if CalculatedValue > 0 then
    ReportRunningTotal1 += CalculatedValue  
else
    ReportRunningTotal2 += CalculatedValue  

Can I specify a condition in a running total? 我可以在总计中指定一个条件吗? If not, how else could I do this? 如果没有,我还能怎么做?

More info: I am doing a running total called GroupRunningTotal of the value of db field BillableHours . 更多信息:我正在对数据库字段BillableHours的值进行一个名为GroupRunningTotal的运行总计。 At change of group, I am comparing GroupRunningTotal to a db field for that group MaxHours , and I display a result of MaxHours - GroupRunningTotal at the group level. 在更改组时,我正在将GroupRunningTotal与该组MaxHours的db字段进行MaxHours ,并在组级别显示MaxHours - GroupRunningTotal的结果。

Appropriate today - Think of it like the electoral college - the person who wins the election does not depend on total number of votes, but of number of votes in the electoral college. 今天是适当的-就像选举学院一样-赢得选举的人并不取决于总投票数,而是取决于选举学院的选票数。

I'm interpreting your question to mean that you want to add up all the negative values in one running total ( RT_Neg ) and all the positive values in another ( RT_Pos ). 我将您的问题解释为意味着您要将一个运行总计( RT_Neg )中的所有负值与另一个运行总计( RT_Pos )中的所有正值相加 How about this: 这个怎么样:

  1. Make the RT_Neg running total. 使RT_Neg总计运行。 Under Field to Summarize , sum your {Tbl1}.{Amount}. 要汇总的字段下 ,对您的{Tbl1}。{Amount}求和。 Under evaluate, enter "{Tbl1}.{Amount}<0" as your custom formula. 在评估下,输入“ {Tbl1}。{金额} <0”作为您的自定义公式。 Never reset. 永远不要重置。

  2. Make the RT_Pos running total. 使RT_Pos总计运行。 Under Field to Summarize , sum your {Tbl1}.{Amount}. 要汇总的字段下 ,对您的{Tbl1}。{Amount}求和。 Under evaluate, enter "{Tbl1}.{Amount}>0" as your custom formula. 在评估下,输入“ {Tbl1}。{金额}> 0”作为您的自定义公式。 Never reset. 永远不要重置。

  3. Insert both running totals in the group footer (if you put them in the header, it may not sum properly) 将两个运行总计插入组页脚中(如果将它们放在页眉中,则可能无法正确求和)

Alternatively, you can: 或者,您可以:

  1. Make a custom formula "If {Tbl1}.{Amount}<0 then {Tbl1}.{Amount} else 0" and make a running total based off that. 编写一个自定义公式“如果{Tbl1}。{Amount} <0,然后{Tbl1}。{Amount} else 0”,然后根据该公式计算运行总计。

I think one of these 2 options will get you to your goal. 我认为这两个选项之一可以帮助您实现目标。

You most likely cannot use one RT field as condition for other RT field. 您很可能无法将一个RT字段用作其他RT字段的条件。 You can use formulas, placed on group footer and evaluated 'whileprintingrecords()'; 您可以使用公式,将其放在组页脚上并评估为“ whileprintingrecords()”; in these formulas you can assign/sum into some variables and display these variables at the end of report. 在这些公式中,您可以分配/求和一些变量,并在报表末尾显示这些变量。 About like next (generic idea only, you need initialization and display routines as well): 关于下一个(仅通用概念,还需要初始化和显示例程):

numbervar rtcurrent := sum({somefield}, {groupfield});
numbervar rtplus;
numbervar rtminus;
if (rtcurrent > 0)
then rtplus := rtplus + rtcurrent
else rtminus := rtminus + rtcurrent;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM