在一张表格上有条件地计算两列之间的差异。

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

Conditionally calculate difference between two columns on a sheet

问题

我有一个名为“allocations”的表格,动态捕获数据:

  • A:小部件ID
  • B:分配给小部件的测试人员1的电子邮件
  • D:测试人员1对小部件的评分
  • E:分配给小部件的测试人员2的电子邮件
  • G:测试人员2对小部件的评分
  • I:评分差异
A B C D E F G H I
widget_id email1 email1thanked rating1 email2 email2thanked rating2 actionsent difference
990235 jack@company.com 0 45 mack@company.com 0 50 0
990236 mack@company.com 0 55 jack@company.com 0 53 0
990231 jack@company.com 0 75 iris@company.com 0 0
990197 iris@company.com 0 mack@company.com 0 25 0
990003 mack@company.com 0 65 iris@company.com 0 85 0

(列C、F、H是发送邮件标志,所以现在不相关)

我想要的操作

在列I中,我希望Excel计算列D和G之间的差异,但只有当列D和G都具有数值值时才这样做。

示例输出:

A B C D E F G H I
widget_id email1 email1thanked rating1 email2 email2thanked rating2 actionsent difference
990235 jack@company.com 0 45 mack@company.com 0 50 0 5
990236 mack@company.com 0 55 jack@company.com 0 53 0 2
990231 jack@company.com 0 75 iris@company.com 0 0
990197 iris@company.com 0 mack@company.com 0 25 0
990003 mack@company.com 0 65 iris@company.com 0 85 0 20

不是这样的
因为我希望只有当D和G两者都具有数值值时,列I才保持为空,而且因为我不知道表格最终会有多少行,所以我不希望像=ABS(G2-D2)这样的操作,并将其复制到所有行。

英文:

I have a sheet allocations dynamically capturing data:

  • A widget ID
  • B email of tester 1 assigned to the widget
  • D widget rating by tester 1
  • E email of tester 2 assigned to the widget
  • G widget rating by tester 2
  • I Differences in the ratings
A B C D E F G H I
widget_id email1 email1thanked rating1 email2 email2thanked rating2 actionsent difference
990235 jack@company.com 0 45 mack@company.com 0 50 0
990236 mack@company.com 0 55 jack@company.com 0 53 0
990231 jack@company.com 0 75 iris@company.com 0 0
990197 iris@company.com 0 mack@company.com 0 25 0
990003 mack@company.com 0 65 iris@company.com 0 85 0

(columns C, F, H are email sent flags, so irrelevant for now)

What I want to happen

In column I, I want Excel to calculate the difference between columns D and G, but only if both columns D and G have numerical values.

Sample output:

A B C D E F G H I
widget_id email1 email1thanked rating1 email2 email2thanked rating2 actionsent difference
990235 jack@company.com 0 45 mack@company.com 0 50 0 5
990236 mack@company.com 0 55 jack@company.com 0 53 0 2
990231 jack@company.com 0 75 iris@company.com 0 0
990197 iris@company.com 0 mack@company.com 0 25 0
990003 mack@company.com 0 65 iris@company.com 0 85 0 20

Not this
Because I want column I to remain empty if not both of D and G have numerical values, and because I don't know upfront how many rows the sheet will end up having, I don't want to do something like =ABS(G2-D2) and copy it over all the way down.

答案1

得分: 1

使用MAP()ISNUMBER()来检查列DG中的值是否为数字。


• 单元格I2中使用的公式

=MAP(D2:D6,G2:G6,LAMBDA(x,y,IF(ISNUMBER(x)*ISNUMBER(y),ABS(y-x),"")))

此外,如果您使用MS365,则不需要使用LAMBDA()迭代。


• 单元格I2中使用的公式

=LET(
       a,D2:D6,
       b,G2:G6,
       IF(ISNUMBER(a)*ISNUMBER(b),ABS(b-a),""))

假设A列将有条目直到最后一行,那么您可以使用以下公式。

=LET(
       a,MATCH(7^89,A:A),
       b,D2:INDEX(D:D,a),
       c,G2:INDEX(G:G,a),
       IF(ISNUMBER(b)*ISNUMBER(c),ABS(c-b),""))

或者,

=LET(
       a,LOOKUP(2,1/(A:A<>""),ROW(A:A)),
       b,D2:INDEX(D:D,a),
       c,G2:INDEX(G:G,a),
       IF(ISNUMBER(b)*ISNUMBER(c),ABS(c-b),""))

或者,

=LET(
       b,DROP(FILTER(D:D,A:A<>""),1),
       c,DROP(FILTER(G:G,A:A<>""),1),
       IF(ISNUMBER(b)*ISNUMBER(c),ABS(c-b),""))

英文:

Using MAP() and ISNUMBER() to check whether the values in columns D & G are numberic or not.

在一张表格上有条件地计算两列之间的差异。


• Formula used in cell I2

=MAP(D2:D6,G2:G6,LAMBDA(x,y,IF(ISNUMBER(x)*ISNUMBER(y),ABS(y-x),"")))

Also, LAMBDA() iteration is not required if you are in MS365

在一张表格上有条件地计算两列之间的差异。


• Formula used in cell I2

=LET(
       a,D2:D6,
       b,G2:G6,
       IF(ISNUMBER(a)*ISNUMBER(b),ABS(b-a),""))

Assuming Column A will have entries till last row, then you could use the following formula.

=LET(
       a,MATCH(7^89,A:A),
       b,D2:INDEX(D:D,a),
       c,G2:INDEX(G:G,a),
       IF(ISNUMBER(b)*ISNUMBER(c),ABS(c-b),""))

Or,

=LET(
       a,LOOKUP(2,1/(A:A<>""),ROW(A:A)),
       b,D2:INDEX(D:D,a),
       c,G2:INDEX(G:G,a),
       IF(ISNUMBER(b)*ISNUMBER(c),ABS(c-b),""))

Or,

=LET(
       b,DROP(FILTER(D:D,A:A<>""),1),
       c,DROP(FILTER(G:G,A:A<>""),1),
       IF(ISNUMBER(b)*ISNUMBER(c),ABS(c-b),""))

在一张表格上有条件地计算两列之间的差异。


huangapple
  • 本文由 发表于 2023年6月22日 13:37:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528853.html
匿名

发表评论

匿名网友

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

确定