In a Google Sheets document, I've got a column which contains multiple values.
I want to get the first 20 values by count, and then group the count of the others.
I've got this working code for now:
=QUERY(B2:B165,"select B, count(B) group by B order by count(B) desc limit 20 label B 'Pubblication venue'")
This will get me how many times a value appears in the column, and limit the results to 20. Now I need the count of the other results (which are ~100).
Let me explain by example. With my code I'm able to get the count of A, B and C. Now I want the count of others.
+-------+----+
| A | 5 |
+-------+----+
| B | 2 |
+-------+----+
| C | 4 |
+-------+----+
| Other | 90 |
+-------+----+
={QUERY(B2:B165,
"select B, count(B)
where B is not null
group by B
order by count(B) desc
limit 20
label B 'Pubblication venue'", 0);
{"Other", COUNTA(IFERROR(QUERY(QUERY(B2:B165,
"select B, count(B)
where B is not null
group by B
order by count(B) desc
offset 20
label count(B)''", 0),
"select Col1", 0)))}}
_____________________________________________________________
={QUERY(B2:B165,
"select B, count(B)
where B is not null
group by B
order by count(B) desc
limit 20
label B 'Pubblication venue'", 0);
{"Other", SUM(IFERROR(QUERY(QUERY(B2:B165,
"select B, count(B)
where B is not null
group by B
order by count(B) desc
offset 20
label count(B)''", 0),
"select Col2", 0)))}}
Related
Is there a way to count how many times a unique row appeared in my sheets?
Here's a sample link:
https://docs.google.com/spreadsheets/d/1z036Q4RtfYPyO0JdcJ9Fcb-adundFdzijNG_1ehsT-4/edit?usp=sharing
I need to count how many times "Apple | 10 | 9 | 1" and "Orange | 12 | 10 | 2" appeared.
I tried using this:
={UNIQUE(A2:D8, false), ARRAYFORMULA(COUNTIF(A2:D8, UNIQUE(A2:D8)))}
However, it counts individual unique cells, not the whole row.
See if this helps
=QUERY(Sheet1!A1:D, "Select A, B, C, D, count(D) where A <>'' group by A, B, C, D label count(D) 'Count'", 1)
I have this table:
Name | Age
Ann | adult
Ann | adult
Andrew | adult
Mike | adult
Ann | teenager
John | teenager
John | teenager
I want this output:
Age | count Name (distinct Names)
adult | 3
teenager | 2
Unfortunately, I can't go further then this formula:
=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 querying?
I know, I can do that with pivot tables with countunique function, but I want to go without pivot tables.
One option could be QUERY + UNIQUE:
=QUERY(UNIQUE(A2:B),"SELECT Col2, COUNT(Col1) WHERE Col2 IS NOT NULL GROUP BY Col2")
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. The LABEL is used as well in order to set the header name for the resulted column.
Reference
ARRAYFORMULA;
UNIQUE;
QUERY.
I am using g-sheet and trying to combine the company name in the case of the unique ID in the interval is equal
UNIQUE ID: 1 1 1 2 2 3
COMPANY NAME: A B C Z E K
Expected output:
1: A, B, C
2: Z, E
3, K
try:
=ARRAYFORMULA(FLATTEN(REGEXREPLACE(TRIM(QUERY(QUERY(
{A2:A&":", B2:B&","},
"select max(Col2)
where not Col1 starts with ':'
group by Col2
pivot Col1"),,9^9)), ",$", )))
How do I list and count unique comma-separated values (column B in the example below) if the number in column A is larger (or smaller) than X? In other words, how do I turn the below table...
Day | Fruits
+--------|--------------------------+
|
20 | Apple, Banana, Pearl
|
24 | Apple, Pearl
|
32 | Banana, Pearl
+
...into this 👇, with criteria: Day < 28.
Fruit | Frequency
+----------|---------------+
|
Apple | 2
|
Pearl | 2
|
Banana | 1
+
A solution proposed by #AdamL in this question is really close to what I want to achieve, but I can't figure out how to list values based on criteria from another column. Here's what Adam came up with:
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN(",",A:A),",")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))
use:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(
IF(IFERROR(SPLIT(B2:B, ","))="",,A2:A&"♦"&TRIM(SPLIT(B2:B, ",")))), "♦"),
"select Col2,count(Col2)
where Col1 < 28
and Col1 is not null
group by Col2
label count(Col2)''"))
I think it's a bit easier to filter on column A first then split:
=ArrayFormula(query(flatten(split(filter(B2:B,A2:A<28,A2:A<>""),",")),"select Col1,count(Col1) where Col1 is not null group by Col1 label Col1 'Fruit',Count(Col1) 'Count'"))
Considering Column 'A' as days and Column 'B' as fruits with row 1 as headers, AdamL's formula works for you with a little tweak as below:
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN(",",B2:B),", ",True)&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))
Hope this solves your problem.
I have data in google sheet I just want to fetch that data in my other sheet but in transpose
Here is ex:
Column A | Column B | Column C
=================================
site1.com | Name 1 | Name 2
site2.com | Name 3 | Name 4
site3.com | Name 5 | Name 6
Want to data like this
Column A | Column B | Column C
=================================
site1.com | site2.com | site3.com
Name 1 | Name 3 | Name 5
Name 2 | Name 4 | Name 6
I don't want to enter formula manually in every row so is arryformula can do this automatic.
I'm trying this but not able to what I want.
=ARRAYFORMULA(TRANSPOSE(Sheet1!$B2:B300 & Sheet1!$L2:L300))
try:
=ARRAYFORMULA({TRANSPOSE(SORT(FILTER(A:A, A:A<>"")));
SUBSTITUTE(TRANSPOSE(SPLIT(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(QUERY(QUERY({A:B; A:A, C:C},
"select count(Col1) where Col1 is not null group by Col1 pivot Col2"),
"offset 1", 0)), SUBSTITUTE(QUERY(QUERY({A:B; A:A, C:C},
"select count(Col1) where Col1 is not null group by Col1 pivot Col2"),
"limit 0"), " ", "♦"), )),,999^99)), " ")), "♦" , " ")})
or you can do just:
=TRANSPOSE(A1:C3)
or:
=TRANSPOSE(INDIRECT("A1:C"&COUNTA(A:A)))
UPDATE:
=QUERY(TRANSPOSE(INDIRECT("Sheet1!A2:L"&COUNTA(Sheet1!A2:A)+1)), "offset 1")