简体   繁体   English

Excel:基于动态范围计算滚动平均值

[英]Excel: Calculate a Rolling Average Based on Dynamic Range

I am trying to calculate rolling average based on a dynamic range. 我正在尝试根据动态范围计算滚动平均值。 To give you an example, my data-set looks like the one below. 举个例子,我的数据集如下所示。 I am trying to calculate the rolling average of the parameter "No. of Users" based on the range "Box no." 我正在尝试根据范围“框号”计算参数“用户数”的滚动平均值。 (12, 13, 14...). (12、13、14 ...)。 Usually, one can calculate rolling average by calculate average for first N rows and then drag it down. 通常,可以通过计算前N行的平均值然后将其向下拖动来计算滚动平均值。 However, the issue here is no. 但是,这里的问题不是。 of users for the Box no. 的用户数。 column vary and therefore I can't use the traditional rolling average method. 列各不相同,因此我不能使用传统的滚动平均法。

Data-set (consider all the values in different row under the column Box No. and Users) 数据集 (考虑“框号和用户”列下不同行中的所有值)

Box No. = 12, 12, 12, 13, 13, 14, 14, 14, 14, 14 箱号= 12,12,12,13,13,13,14,14,14,14,14

Users = 5, 5, 8, 6, 8, 10, 8, 3, 5, 1 用户= 5、5、8、6、8、10、8、3、5、1

So, I am looking for a result like this. 因此,我正在寻找这样的结果。

Result (consider all the values in different row under the column Box No. and Rolling Average for No. Users) 结果 (考虑“箱号”和“用户滚动平均值”列下不同行中的所有值)

Box No. = 12, 13, 14 箱号= 12,13,14

Rolling Average for (No. of Users) = 6, 7, 5.4 (用户数)滚动平均值= 6、7、5.4

Any help would be appreciated. 任何帮助,将不胜感激。

When you say moving average, do you mean a sort of "average if" that is rolling? 当您说移动平均线时,您是说一种正在滚动的“平均水平”吗? Your example simply shows a conditional average, not a rolling one. 您的示例仅显示了条件平均值,而不是滚动平均值。

It seems like your problem could be solved using averageif() . 看来您的问题可以使用averageif()解决。 For more complex cases, you can use the formula average() with an if() formula inside that specifies the conditions you want to match so that the average is computed. 对于更复杂的情况,可以将公式average()与内部的if()公式配合使用,该公式指定要匹配的条件,以便计算平均值。 This becomes an array formula and must be entered as Ctrl+Shift+Enter or equivalent. 这将成为一个数组公式,必须以Ctrl + Shift + Enter或等效形式输入。

Let's say you have your Box data in B1:K14 and your Users data in B2:K14. 假设您的Box数据位于B1:K14中,而Users数据位于B2:K14中。 You'll get your results for Box 12 with both: 您将同时获得方框12的结果:

{=AVERAGE(IF(B1:K1=12,B2:K2,""))} {= AVERAGE(IF(B1:K1 = 12,B2:K2 “”))}

and

=AVERAGEIF(B1:K1,12,B2:K2) = AVERAGEIF(B1:K1,12,B2:K2)

Of course, the conditions can be in adjacent cells so that it can easily be extended to different Boxes or even Users. 当然,条件可以在相邻的单元格中,以便可以轻松地将其扩展到其他Box甚至User。

There are two parts to this. 这有两个部分。

PART 1 第1部分

To address the dynamic range, I suggest that you use a Table. 为了解决动态范围,建议您使用表格。 If your data set is this: 如果您的数据集是这样的:

数据集

then click in the dataset and select Table from the Insert command tab. 然后单击数据集,然后从“ Insert命令选项卡中选择“ Table ”。 Make sure you have My table has headers selected. 确保您的“ My table has headers选择My table has headers

The result should look like this: 结果应如下所示:

表

Colors can vary based on your version and setup. 颜色可能会因您的版本和设置而异。

PART 2 第2部分

To get your averages based on this table, click in the table and select Pivot Table from the Insert command tab. 要获取基于此表的平均值,请单击表,然后从“ Insert命令选项卡中选择“ Pivot Table ”。 Accept the defaults and you will end up on new sheet with a blank Pivot Table. 接受默认值,您将最终在空白页数据透视表的新表上。

Drag the Box No. field down to the Rows block and the Users field down to the Values block. Box No.字段向下拖动到Rows块,将Users字段向下拖动到Values块。 Click the arrow to the right of the User name in the Values block and select Value Field Settings... Then select Average in Summarize Values By . 单击“ Values块中User名右侧的箭头,然后选择Value Field Settings...然后在“ Summarize Values By依据Value Field Settings...选择“ Average You can also rename the displayed field name in Custom Name: . 您也可以在“ Custom Name:重命名显示的字段名称。

Note: After adding data, right click in the Pivot Table and select Refresh to see the new data. 注意:添加数据后,右键单击数据透视表,然后选择“ Refresh以查看新数据。

在此处输入图片说明

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

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