简体   繁体   English

Excel Pivot - 计算平均值 > XX

[英]Excel Pivot - Calculate average for values > XX

Data table simplified - read only:数据表简化 - 只读:

 <table border=1> <tr><th>Date</th><th>Hours</th></tr> <tr><td>Jan. 1</td><td>6.5</td></tr> <tr><td>Jan. 2</td><td>8.5</td></tr> <tr><td>Jan. 3</td><td>7.5</td></tr> <tr><td>Jan. 4</td><td>9.0</td></tr> </table>

Now I would like a pivot table that can calculate the average number of hours - only taking into account the days where the number of hours are > 8.0.现在我想要一个可以计算平均小时数的 pivot 表 - 仅考虑小时数 > 8.0 的天数。 Ie. IE。 for the above data the pivot should return 8.75.对于上述数据,pivot 应返回 8.75。

I've tried with calculated field: =If(Hours > 8, Hours, NULL) - or blanks instead of null or similar.我已经尝试使用计算字段:=If(Hours > 8, Hours, NULL) - 或空白而不是 null 或类似的。

Please help.请帮忙。

You don't need a Pivot table.您不需要 Pivot 表。 Just use =AverageIf([Range of Hours],">8")只需使用=AverageIf([Range of Hours],">8")

Edit:编辑:

To achieve through Pivot Table, I can only think of using "measure".要通过Pivot表来实现,我只能想到用“测量”。 But it could be quite slow for 120k rows as the Filter() function need to go through each row one by one.但是对于 120k 行来说它可能会很慢,因为Filter() function 需要 go 逐行遍历每一行。

  1. create a the Pivot Table with the checkbox "Add this data to the Data Model" clicked;创建一个 Pivot 表并单击“将此数据添加到数据模型”复选框;
  2. Right-click on the "Range" (or the table name if your data is a table) in the Field List and choose "Add Measure"右键单击字段列表中的“范围”(如果您的数据是表格,则为表格名称),然后选择“添加度量”
  3. Enter the measure's info and use =SUMX(Range, if(Range[Hour]>8, Range[Hour],0))/ COUNTROWS(FILTER(ALL(Range), Range[Hour]>8)) as formula (replace "Range" with Table name if source data is a table).输入度量的信息并使用=SUMX(Range, if(Range[Hour]>8, Range[Hour],0))/ COUNTROWS(FILTER(ALL(Range), Range[Hour]>8))作为公式(替换如果源数据是表格,则带有表格名称的“范围”)。 And click "OK".并单击“确定”。

Then, you can use this measure to get the average value you want.然后,您可以使用此度量来获得所需的平均值。

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

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