简体   繁体   English

Crystal报告用于获取组“最小”和“最大”运行总计的平均值的公式

[英]Crystal reports formula for getting an average of group Minimum and Maximum running totals

First question here. 这里的第一个问题。

My question is how do I get an average of running total minimums and an average of running total maximums? 我的问题是如何获得运行总最小值的平均值和运行总最大值的平均值? I'm thinking I will need to use a formula rather than running totals but I don't know what that formula is. 我想我将需要使用公式而不是总计,但我不知道该公式是什么。

I'm writing a crystal report that gives occurrences of a thing over time. 我正在写一份水晶报告,该报告会随着时间的推移出现某件事。 How many times did a thing happen each month for a year grouped by month. 在按月分组的一年中,每个月发生某件事多少次。 Also, how long did it take to happen? 另外,发生了多长时间? Average time, Minimum Time, Maximum Time. 平均时间,最小时间,最大时间。

Year     | Month  | How Many | Average? (days) | Minimum Time | Maximum Time

2017

January  | 15      | 5       | 2           | 16          
February | 7       | 4       | 1           | 10      
March    | 20      | 6       | 4           | 12       
Average  | 14      | 5       | 2.33        | 12.66 

I am using a running total in the month groups to get the average, min, and max for each month. 我使用月份组中的运行总计来获取每个月的平均值,最小值和最大值。

But when I get to the average for all the groups, I want the average for all the minimums and the average for the maximums. 但是,当我达到所有组的平均值时,我想要所有最小值的平均值和最大值的平均值。 I don't want the minimum for the year which would be 1. I could use a running total for that. 我不希望该年度的最小值为1。我可以为此使用总计。 I want 2.33. 我要2.33。 Crystal doesn't let me to a running total average on running total minimums. Crystal不允许我以运行总最小值为运行总平均值。

I hope that makes sense. 我希望这是有道理的。 Thanks in advance for your help. 在此先感谢您的帮助。

I would use a Formula Field to create a variable to accumulate values and then a second Formula Field to count the number of times it has accumulated a value. 我将使用一个公式字段来创建一个变量以累加值,然后使用第二个公式字段来计算其累加值的次数。 Then you divide the accumulated total by the counter to get your average. 然后,将累计总数除以计数器即可得出平均值。

The formula for the accumulator would be... 累加器的公式为...

WhilePrintingRecords;
Shared Numbervar MinsAccumulator := MinsAccumulator + {#Minimum_Time};

The formula for the counter would be... 计数器的公式为...

WhilePrintingRecords;
Shared Numbervar counter = counter + 1;

Do keep in mind though, if the section you use this within is repeated at all, then you will also need a formula field to reset the values of your variables to zero. 但是请记住,如果您在其中使用的部分完全重复了,那么您还将需要一个公式字段将变量的值重置为零。 This would look like this... 看起来像这样...

WhilePrintingREcords;
Shared Numbervar counter = 0;

Just drop each formula field into the section where you want them to be evaluated and then suppress the fields so they don't display. 只需将每个公式字段放到要对其进行评估的部分中,然后隐藏该字段以使它们不显示。 Then you can create additional formula fields to display the value of the variable you want to use in your report. 然后,您可以创建其他公式字段以显示要在报表中使用的变量的值。 here is the formula for displaying the variable. 这是显示变量的公式。

Shared Numbervar counter;
counter;

If you aren't familiar with using variables in Crystal Report just respond back and I can explain them in more detail. 如果您不熟悉在Crystal Report中使用变量,请回信,我可以更详细地解释它们。 They can be a little tricky at first. 一开始它们可能会有些棘手。

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

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