[英]How to query count of unique features in google sheets?
I have this table:我有这张桌子:
Name | Age
Ann | adult
Ann | adult
Andrew | adult
Mike | adult
Ann | teenager
John | teenager
John | teenager
I want this output:我想要这个 output:
Age | count Name (distinct Names)
adult | 3
teenager | 2
Unfortunately, I can't go further then this formula:不幸的是,我不能再 go 然后这个公式:
=QUERY(table; "select B, count(A) group by B"; 1)
where the 'table' is the named range with input data.其中“表”是具有输入数据的命名范围。 And it gives me this:
它给了我这个:
Age | count Name
adult | 4
teenager | 3
I need something like:我需要类似的东西:
=QUERY(table; "select B, count(unique(A)) group by A"; 1)
which obviously doesn't work.这显然是行不通的。
So, how can I achieve my target output with quering?那么,我怎样才能通过查询来实现我的目标 output 呢? I know, I can do that with pivot tables with countunique function, but I want to go without pivot tables.
我知道,我可以使用带有 countunique function 的 pivot 表来做到这一点,但我想在没有 pivot 表的情况下使用 go。
You can also make use of this formula:你也可以使用这个公式:
=ARRAYFORMULA(QUERY(UNIQUE({B:B, B:B & A:A, A:A}), "SELECT Col1, COUNT(Col1) WHERE Col1 IS NOT NULL GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL COUNT(Col1)'count Name'", 1))
After后
Explanation解释
The formula makes use of the following functions:该公式使用以下函数:
ARRAYFORMULA
UNIQUE
QUERY
In order to find the unique values, the UNIQUE
is used for the range needed for the query ( A:B
) such that the sorting and counting is done on this range.为了找到唯一值,
UNIQUE
用于查询所需的范围 ( A:B
),以便在此范围内完成排序和计数。 The LABEL
is used as well in order to set the header name for the resulted column. LABEL
也用于为结果列设置 header 名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.