如何使用Office365 Excel数组公式将此标准公式转换?

huangapple go评论51阅读模式
英文:

Using Office365 Excel array formulas, how to convert this standard formula?

问题

这两个公式是相同的,只是第一个不是数组公式,而第二个是。如何将第一个公式转换为数组公式?在使用数组公式时出现循环逻辑。

标准公式(正常工作,没有循环逻辑):

=LET(a, A2, b, B2, c, C2, d, D1, e, E1,
    dd, IF(a = 1, 0, d),
    ee, IF(a = 1, 0, e),
    (b * c + dd * ee ) / (b + dd) )

数组公式(循环逻辑错误):

=LET(a, A9:A12, b, B9:B12, c, C9:C12, d, D8:D11, e, E8:E11,
    dd, IF(a = 1, 0, d),
    ee, IF(a = 1, 0, e),
    (b * c + dd * ee ) / (b + dd) )

这个公式是两组数字的相对简单的加权平均值。试图将其转换为数组公式。先前的结果在下一行中使用,只有在第一行没有先前的结果。

困难之处在于如何在计算当前单元格时引用先前的结果单元格。

英文:

These two formulas are the same, except the first one is not an array formula and the second one is. How can the first formula be converted to an array formula? Getting circular logic when using the array formula.

Standard Formula (works fine, no circular logic):

=LET(a, A2, b, B2, c, C2, d, D1, e, E1,
    dd, IF(a = 1, 0, d),
    ee, IF(a = 1, 0, e),
(b * c + dd * ee ) / (b + dd)  )

Array Formula (circular logic error):

=LET(a, A9:A12, b, B9:B12, c, C9:C12, d, D8:D11, e,E8:E11,
    dd, IF(a = 1, 0, d),
    ee, IF(a = 1, 0, e),
(b * c + dd * ee ) / (b + dd)  )

The formula is a fairly simple weighted average of two sets of numbers. Trying to convert it to an array formula. The previous result is used on the following row, except on the first row where there is no previous result.

The difficulty is in how to reference the previous result cell when calculating the current cell.

如何使用Office365 Excel数组公式将此标准公式转换?

Data:

Seq B C D
1 100 1.00 -
2 100 3.00 800
3 250 2.00 200
4 400 5.00 300

答案1

得分: 1

INDEX每个数组并使用SCAN返回值:

=LET(
    a, A9:A12, 
    b, B9:B12, 
    c, C9:C12, 
    d, D8:D11,
    dd, IF(a = 1, 0, d),
    SCAN(0,a,LAMBDA(z,y,(INDEX(b,y)*INDEX(c,y)+INDEX(dd,y)*z)/(INDEX(b,y)+INDEX(dd,y)))))

如何使用Office365 Excel数组公式将此标准公式转换?

英文:

INDEX each array and use SCAN to return the values:

=LET(
    a, A9:A12, 
    b, B9:B12, 
    c, C9:C12, 
    d, D8:D11,
    dd, IF(a = 1, 0, d),
    SCAN(0,a,LAMBDA(z,y,(INDEX(b,y)*INDEX(c,y)+INDEX(dd,y)*z)/(INDEX(b,y)+INDEX(dd,y)))))

如何使用Office365 Excel数组公式将此标准公式转换?

答案2

得分: 1

  • 使用SCAN和位移进行累积
  • 丢弃最后一行(DROP)的最后一列(TAKE),并在其上堆叠一个零(VSTACK):
=LET(data,B2:D5,
    dt,HSTACK(DROP(data,,-1),VSTACK(0,DROP(TAKE(data,,-1),-1)))),
SCAN(0,SEQUENCE(ROWS(dt)),LAMBDA(sr,r,
    LET(b,INDEX(dt,r,1),c,INDEX(dt,r,2),d,INDEX(dt,r,3),
(b*c+d*sr)/(b+d)))))
英文:

Accumulate Using SCAN With a Shift

  • Lose the last row (DROP) of the last column (TAKE) and stack a zero on top of it (VSTACK):

    VSTACK(0,DROP(TAKE(data,,-1),-1))
    
=LET(data,B2:D5,
    dt,HSTACK(DROP(data,,-1),VSTACK(0,DROP(TAKE(data,,-1),-1))),
SCAN(0,SEQUENCE(ROWS(dt)),LAMBDA(sr,r,
    LET(b,INDEX(dt,r,1),c,INDEX(dt,r,2),d,INDEX(dt,r,3),
(b*c+d*sr)/(b+d)))))

huangapple
  • 本文由 发表于 2023年6月2日 02:42:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384813.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定