英文:
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()
来检查列D
和G
中的值是否为数字。
• 单元格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),""))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论