简体   繁体   English

Excel Pivot表:仅基于组的第一行的计算字段

[英]Excel Pivot table: Calculated field based on only the first row of a group

I've got the following data and pivot table: 我有以下数据和数据透视表:

在此处输入图片说明

The Total column in the pivot table is the sum of the following calculated field: 数据透视表中的“ 总计”列是以下计算字段的总和:

=start-TIME(7, 30, 0)

I know that this calculation is wrong for what I want to achieve. 我知道这种计算对我想要达到的目标是错误的。 I need to know how much delay I have had on each day to start the work. 我需要知道每天开始工作有多长时间。 eg on 1-Oct-12, assuming I should have started my work at 7:30, 8:00 - 7:30 which yields 30 minutes delay, 1 hour delay for 2-Oct-12 and 50 minutes for 3-Oct-12. 例如,假设我应该在7:30、8:00-7:30开始工作,那么该工作应该在30:30、8:00-7:30进行,这会导致30分钟的延迟,12月2日的延迟时间为1小时,而3Oct的延迟时间为50分钟12
So my question is, how can I have a calculated field based on only the first row of each group in a pivot table? 所以我的问题是,如何仅基于数据透视表中每个组的第一行来计算字段?

I tend to avoid calculated fields and do the calculation in the source data if possible. 我倾向于避免计算字段,并在可能的情况下在源数据中进行计算。 So in this case I'd add a delay column to your source data, with a calculation that sums the difference only for the first row for each date: 因此,在这种情况下,我会将延迟列添加到您的源数据中,并进行计算,该计算仅对每个日期的第一行的差求和:

=IF(COUNTIF($A$2:$A2,$A2)=1,B2-TIME(7,30,0),0)

在此处输入图片说明

Then you can pivot on the sum of delay. 然后,您可以考虑延迟的总和。 Format the delay pivot field like [h]:mm . 格式化延迟枢轴字段,例如[h]:mm

在此处输入图片说明

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

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