在Excel中按条件进行唯一计数

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

Unique count with criteria in Excel

问题

Excel问题:

我有2个标签:

标签1,主要数据:
在Excel中按条件进行唯一计数

标签2,编辑此标签
在Excel中按条件进行唯一计数

在标签2中,
我想要显示一组地址(第3列)的唯一计数。
当我输入第1行的唯一ID时,我的结果应该自动更新第2列和第3列。我正在使用xlookup从标签1更新第2列。如何获得第3列的唯一计数?

这可能吗?

我尝试过https://www.statology.org/excel-count-unique-by-group/,但公式在添加内容时会出现问题。希望有一个可以在添加新行时更新的公式。

英文:

Excel question:

I have 2 tabs:

Tab 1, primary data:
在Excel中按条件进行唯一计数

Taba 2, editing this taab
在Excel中按条件进行唯一计数

In tab 2,
I want to show unique count of addresses for 1 group (column3).
My result should automatically update column 2 and 3 when I input Row 1 unique Id. I'm using xlookup to update column 2 from tab 1. How do I get column 3 unique count?

Is this possible?

I tried https://www.statology.org/excel-count-unique-by-group/ and the formula kept breaking when something was added. Want a formula that updates if new rows are added.

答案1

得分: 3

Unique Count With Criteria

=LET(di,A2:A10,si,'Tab1'!A2:A10,sg,'Tab1'!B2:B10,sa,'Tab1'!C2:C10,
    dg,XLOOKUP(di,si,sg),dgu,UNIQUE(dg),
    uc,BYROW(dgu,LAMBDA(r,ROWS(UNIQUE(FILTER(sa,sg=r))))),
    gm,INDEX(uc,XMATCH(dg,dgu)),
HSTACK(dg,gm))
  • You could add some error handling by using the 4th parameter of XLOOKUP for the Group column and by using IFERROR for the Count column (not used in the screenshot).
=LET(di,A2:A11,si,'Tab1'!A2:A10,sg,'Tab1'!B2:B10,sa,'Tab1'!C2:C10,
    dg,XLOOKUP(di,si,sg,""),dgu,UNIQUE(dg),
    uc,BYROW(dgu,LAMBDA(r,ROWS(UNIQUE(FILTER(sa,sg=r))))),
    gm,IFERROR(INDEX(uc,XMATCH(dg,dgu)),""),
HSTACK(dg,gm))
  • Note that you can get rid of the gm variable. Its purpose is just to make it a bit more readable.
英文:

Unique Count With Criteria

=LET(di,A2:A10,si,'Tab1'!A2:A10,sg,'Tab1'!B2:B10,sa,'Tab1'!C2:C10,
    dg,XLOOKUP(di,si,sg),dgu,UNIQUE(dg),
    uc,BYROW(dgu,LAMBDA(r,ROWS(UNIQUE(FILTER(sa,sg=r))))),
    gm,INDEX(uc,XMATCH(dg,dgu)),
HSTACK(dg,gm))

在Excel中按条件进行唯一计数

  • You could add some error handling by using the 4th parameter of XLOOKUP for the Group column and by using IFERROR for the Count column (not used in the screenshot).
=LET(di,A2:A11,si,'Tab1'!A2:A10,sg,'Tab1'!B2:B10,sa,'Tab1'!C2:C10,
    dg,XLOOKUP(di,si,sg,""),dgu,UNIQUE(dg),
    uc,BYROW(dgu,LAMBDA(r,ROWS(UNIQUE(FILTER(sa,sg=r))))),
    gm,IFERROR(INDEX(uc,XMATCH(dg,dgu)),""),
HSTACK(dg,gm))
  • Note that you can get rid of the gm variable. Its purpose is just to make it a bit more readable.

答案2

得分: 1

=LET(in, A2:C7, B, INDEX(in,,2), C, TAKE(in,,-1), HSTACK(TAKE(in,,2), MAP(B, LAMBDA(x, ROWS(UNIQUE(FILTER(C,B=x,0)))))))

Another alternative:
=LET(in, A2:C7, B,INDEX(in,,2), C,TAKE(in,,-1), uxC,UNIQUE(C), cnts, MMULT(N(COUNTIFS(B, B, C,TOROW(uxC))>=1), SEQUENCE(ROWS(uxC))^0), HSTACK(TAKE(in,,2), cnts))

Here is the output:
在Excel中按条件进行唯一计数

英文:

Assuming no Excel version constraints as per the tags listed in the question:

=LET(in, A2:C7, B, INDEX(in,,2), C, TAKE(in,,-1),
 HSTACK(TAKE(in,,2), MAP(B, LAMBDA(x, ROWS(UNIQUE(FILTER(C,B=x,0)))))))

Another alternative:

=LET(in, A2:C7, B,INDEX(in,,2), C,TAKE(in,,-1), uxC,UNIQUE(C),
 cnts, MMULT(N(COUNTIFS(B, B, C,TOROW(uxC))>=1), SEQUENCE(ROWS(uxC))^0),
 HSTACK(TAKE(in,,2), cnts))

Here is the output:
在Excel中按条件进行唯一计数

答案3

得分: 0

第二个表格中,你可以使用以下公式:

第一列公式:

=Table1[@UniqueID]

第二列公式:

=Table1[@Group Name]

第三列公式:

=COUNTIFS(Table1[Address], Table1[@Address], Table1[Group Name], [@[Group Name]])

英文:

If you are able to format both sets of data as tables then in the second table you can do

column 1 formula:

    =Table1[@UniqueID]

column 2 formula:

    =Table1[@Group Name]

column 3 formula

    =COUNTIFS(Table1[Address],Table1[@Address],Table1[Group Name],[@[Group Name]])

huangapple
  • 本文由 发表于 2023年4月7日 02:21:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952617.html
匿名

发表评论

匿名网友

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

确定