2

这个答案中,给出了以下公式。

{=PERCENTILE(IF(COLUMN(INDIRECT("1:"&MAX(Data!N3:N15)))<=Data!N3:N15,Data!M3:M15,""),0.25)}

它应该计算带有权重的数据的前四分位数。

我一直试图理解这个公式的含义,但我不能。

首先,大括号是什么?(可能是一个愚蠢的问题。)

其次,<=当给定两个数据范围作为操作数时,运算符会做什么?

第三,如果不管 if 语句中的条件是什么,返回的数据只是 value 列,这怎么可能给出正确的答案?在我看来,公式的作用是

  • 如果满足奇怪的条件,则计算 value 列的第一个四分位数。
  • 如果不是,则计算“”的第一个四分位数。

这似乎完全错误......

另外,在哪里可以找到 Excel 函数和运算符的完整手册?在线帮助文​​件没有说明比较两个范围。

4

3 回答 3

4

Personally I wouldn't use the quoted formula - I doubt if it does exactly what the author thinks it does and in some circumstances it will give incorrect results. You can see the problem because this part

=COLUMN(INDIRECT("1:"&MAX(Data!N3:N15))

returns exactly the same thing if MAX(Data!N3:N15) is 2 or 200. If MAX(Data!N3:N15)=2 you get

=COLUMN(INDIRECT("1:2"))

and I assume the author's intent is to return an array like {1,2}.......but it doesn't do that. INDIRECT("1:2") gives you 1:2 which is interpreted as the whole of rows 1 and 2 so =COLUMN(1:2) gives you the numbers of all columns (which is either 1 to 256 or 1 to 16384 depending on which version of excel you are using or whether you are using compatability mode or not).

You can test that by using this formula in a cell

=COUNT(COLUMN(INDIRECT("1:"&MAX(Data!N3:N15))))

confirmed with CTRL+SHIFT+ENTER

You'll either get 256 or 16384 but that doesn't depend on the values in column N at all.

The formula may well give you the correct result but it might not work correctly if any values in Data!N3:N15 are > 256 (or 16384 depending on version).

This version of the formula should do as intended in all cases:

=PERCENTILE(IF(TRANSPOSE(ROW(INDIRECT("1:"&MAX(Data!N3:N15)))) <=Data!N3:N15,Data!M3:M15,""),0.25)

.....but to explain how it works lets look at a cut down version with only 4 rows, i.e.

=PERCENTILE(IF(TRANSPOSE(ROW(INDIRECT("1:"&MAX(Data!N3:N6))))<=Data!N3:N6,Data!M3:M6,""),0.25)

and assume that M3:M6 contains these values - 10, 75, 15, 23 and that N3:N6 contains these values 1,2,3,4,

Now MAX(Data!N3:N6) = 4 so INDIRECT gives you "1:4" and that is passed to the ROW function so you get an array like {1;2;3;4} [which is a "column" of values] but TRANSPOSE converts that to {1,2,3,4} [which is a "row" of values] - the reason for that conversion is because when a column is compared to a row or vice versa it compares every value in one array with every value in the other array which is what is needed here (giving a 4x4 matrix of values as a result).

Now when we do that every value in {1,2,3,4} is <= 4 (N6 value) but only 3 are <= 3 (N5 value), only 2 are <= 2 (N4 value) etc. so the array that is passed to the PERCENTILE function correctly returns 1 value of 10, 2 values of 75, 3 values of 15 and 4 values of 23 (the other values are "" blanks which PERCENTILE ignores)

The result of my example would be 15 and the original formula also gives 15.......but as explained above the original formula might get incorrect results with larger numbers - e.g. I'm testing with compatability mode in Excel 2007 and if I change N4 to 4000 and N6 to 1000 I now expect the result to be 75 (which is the result my formula gives) .....but original formula gives 23.

于 2013-08-13T12:12:18.343 回答
3
  1. 最里面的操作是MAX(Data!N3:N15),这会查找 range 中的最大值M3:M15。假设最大值为 10。
  2. 第二个操作是INDIRECT("1:"&10)INDIRECT变成范围1:10
  3. COLUMN返回一个数组,其中包含 range 的列号1:10。(如果是范围A1:B1,您将获得数组{1,2}。如果是B1:D1,则数组将是{2,3,4}。因此COLUMN(1:10)返回{1, 2, 3, etc...}
  4. Data!N3:N15应该很容易理解。范围本身是一个数组。假设它包含以下值:{2, 3, , 5, etc...}
  5. 比较:{1, 2, 3, etc...} <= {2, 3, , 5, etc...}。如果满足比较,则返回 range 中的值Data!M3:M15。假设这个包含{15, 14, 13, 12, 11, etc... }.

    • 第一次比较: 1 <= 2 (两个数组的第一个元素)为真,因此返回15
    • 第二次比较: 2 <= 3 (两个数组的第二个元素)为真,因此返回14
    • 第三次比较: 3 <= "" (两个数组的第三个元素)为假,因此,""根据IF其他结果返回。
    • ETC...

    由此产生的数组是{15, 14, "", 12, etc... }

  6. 获取此数组的百分位数。

由于这是一个数组公式,因此必须使用Ctrl++来使用该Shift公式Enter。无论何时执行此操作,大括号都会自动环绕公式。

附录我之前没有添加(这一点是我在看到巴里·胡迪尼的回答之前会放的):

无论范围内的最大值是什么N3:N15(除了 256 或 16384 以上,具体取决于 excel 版本),COLUMN(INDIRECT("1:"&MAX(Data!N3:N15)))都会返回一个常数值,我认为这会以某种方式使公式出错。

不过,要获得更好的解释,请参阅barry houdini 的回答

于 2013-08-13T10:03:22.733 回答
0

要回答问题的第一部分 - 大括号表示数组公式(函数)。PERCENTILE功能就是其中之一。输入公式需要用到:CTRL+SHIFT+ENTER,纯ENTER是不够的。

你可以在这里阅读更多关于它的信息:

于 2013-08-13T10:02:34.517 回答