I can't find a way to simplify a query to get a similar result to a pivot.
Although a pivot table is easy, I would prefer to use a query because I can then personalise headers.
Here's the link with the data :
https://docs.google.com/spreadsheets/d/1R461nv2lD4efpuUuDonFMYGnLH510n7gwpbzG2WAUaw/edit?usp=sharing.
This is the working embedded queries :
= query(query(Data!A1:C, " SELECT B,count(B) WHERE B is not null GROUP BY B,C ORDER BY B ASC "), "SELECT Col1, Count(Col1) group by Col1 LABEL Col1 'Status',Count(Col1) 'Count'",1 )
This is the query I'd like to use with a pivot clause :
=query(Data!A1:C, "Select B, count(C) group by count(C) Pivot C" ,1)
Here's what I'm looking for :
Try
={"Status","Count(Categories)";transpose(query(unique(B:C),"select count(Col2) where Col2 is not null pivot Col1",1))}
or simplier
=query(unique(B:C),"select Col1, count(Col2) where Col2 is not null group by Col1",1)
if you want to pivot C column it should be:
=QUERY({Data!A1:C, Data!C1:C},
"select Col2,count(Col3) where Col1 is not null group by Col2 pivot Col4", 1)
Related
I am trying to query two columns of data in Google Sheets and count how many times the values occur.
I have made a Google Sheets formula which works but only returns data in the first column.
=QUERY(QUERY({D2:D,E2:E}, "select Col1, count(Col1) group by Col1"), "select Col1, Col2 order by Col2 desc, Col1 limit 45", 0)
How can I query and count data from both columns together?
DESIRED RESULT
2.38 / 2
5.38 / 2
...
I have made a Google Sheet showing an example. This can be copied by going to File-Make a Copy
https://docs.google.com/spreadsheets/d/1S5fE43JPVgUhZFVx-rjowkCy8N6p_ziIhIWe4MweiXQ/edit?usp=sharing
If your formula gives the correct output, you may need to change your comma with semicolon. That way all your data will be grabbed as a single column:
=QUERY(QUERY({D2:D;E2:E}, "select Col1, count(Col1) group by Col1"), "select Col1, Col2 order by Col2 desc, Col1 limit 45", 0)
Please try:
=QUERY({D2:D;E2:E},"Select Col1, COUNT(Col1) WHERE Col1 IS NOT NULL GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL COUNT(Col1)''")
What's the formula to find which is the most frequent character in a cell in Google Sheets?
E.G. In cell N8 it says: "What's your name?". I'd like the formula to return "a", as it is the most frequent character in N8.
you can get the total distribution like this:
=QUERY(FLATTEN(REGEXEXTRACT(A1, REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) group by Col1 order by count(Col1) desc label count(Col1)''")
notice that two empty spaces are counted as well
if you want to skip them use:
=QUERY(FLATTEN(REGEXEXTRACT(A1, REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) where Col1 <> ' ' group by Col1
order by count(Col1) desc label count(Col1)''")
also, keep in mind that this is case-sensitive:
to make it case-insensitive use:
=QUERY(FLATTEN(REGEXEXTRACT(LOWER(A1), REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) where Col1 <> ' ' group by Col1
order by count(Col1) desc label count(Col1)''")
so to get the top value only use:
=INDEX(QUERY(FLATTEN(REGEXEXTRACT(LOWER(A1), REPT("(.)", LEN(A1)))),
"select Col1,count(Col1) where Col1 <> ' ' group by Col1
order by count(Col1) desc label count(Col1)''"), 1, 1)
This should work:
=index(Sort(filter({LEN(substitute($A$1,mid($A$1,ROw(A:A),1),"")),mid($A$1,ROw(A:A),1)},Row(A:A)<= LEN(A1)),1,true),1,2)
I'm not sure what you'd expect for when there's a tie, but it would consistently return the character most used. If you wanted to skip spaces, you could do this...
=index(Sort(filter({LEN(substitute($A$1,mid(substitute($A$1,"
",""),ROw(A:A),1),"")),mid(substitute($A$1," ",""),ROw(A:A),1)},Row(A:A)
<= LEN(substitute(A1," ",""))),1,true),1,2)
I am trying to calculate a count of how many times a course is listed in different columns and return the count in a list of all the courses found in those columns.
I have a spreadsheet that shows the start of my formula...
query(UNIQUE({C2:C21; F2:F21;I2:I21}),"select C,F,I, count(C), count(F), count(I) where B is not null group by C,F,I")
Clear cells A23, A24 and B23 and then try in A23
=query({C2:C21; F2:F21;I2:I21},"select Col1, count(Col1) where Col1 <> '' group by Col1 label Col1 'Fall Courses', Count(Col1) 'Count'")
and see if that helps?
If it does, you can repeat the same logic for 'winter' and 'spring'.
Alternatively, you can also try this single formula
=query(ArrayFormula(split(transpose(split(textjoin("~", true, regexreplace(C1:K1, "(Winter|Spring|Fall)", "_$1")&"_"&C2:K21), "~")), "_")), "Select Col3, Count(Col3) where Col3 <>'' group by Col3 pivot Col2", 0)
I have a big table with repeating dates in Column A and some repeating names in Column B. I need to count how many A there are in each month if we count one A for one date. So if there are two A's for 01.06.2021, so it will be counted as 1. The list of A, B, C contains about 20 names.
try:
=INDEX(REGEXREPLACE(""&QUERY(UNIQUE({A:B\ TEXT(A:A; "mm\×mmmm yyyy")});
"select Col2, count(Col2) where Col2 is not null group by Col2 pivot Col3");
"(^\d+×)"; ))
or if you need numeric numbers:
=INDEX(IFERROR(REGEXREPLACE(QUERY(UNIQUE({A:B\ TEXT(A:A; "mm\×mmmm")});
"select Col2, count(Col2) where Col2 is not null group by Col2 pivot Col3");
"(^\d+×)"; ); QUERY(UNIQUE({A:B\ TEXT(A:A; "mm\×mmmm")});
"select Col2, count(Col2) where Col2 is not null group by Col2 pivot Col3")))
I have a formula that gets a unique list of titles from pipe-delimited string in a column and there counts
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN("|",Elements!$H2:$H),"|")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) ''",0))
I need to sort the counts in a descending manor, I have tried adding order by Col2 Desc
=ArrayFormula(QUERY(TRANSPOSE(SPLIT(JOIN("|",Elements!$H2:$H),"|")&{"";""}),"select Col1, count(Col2) group by Col1 label count(Col2) order by Col2 Desc''",0))
But I get unable to parse ...
Thank you
use:
=INDEX(QUERY(TRANSPOSE(SPLIT(JOIN("|", Elements!H2:H), "|")&{"";""}),
"select Col1,count(Col2)
group by Col1
order by count(Col2) desc
label count(Col2)''", 0))