Query multiple columns of data in Google Sheets and count number occurrences - google-sheets

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)''")

Related

Max Sum of row within date range - Google Sheets

I am using Google Sheets.
I have names in first column, dates in first row, and numbers for each name/date.
I want to return the name and sum of numbers for the person who's sum of numbers is the largest (within date range.)
A cell formula for this would be better than a script.
It sounds straight forward but am going in circles and would appreciate help. Thanks Newman
Thank you.
try:
=INDEX(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"))
and for just 1 record:
=INDEX(QUERY(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"), "limit 1", 0)

Query Formula using Google Sheets - count data from multiple columns and return results in a single column

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)

Google sheets: Count unique values in Column B according to unique values in Column A

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")))

add order by to query formula that gets unique list and count from delimited strings in a column Google sheets

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))

Count how many times certain text combinations occurs in certain columns

I have a data set with multiple columns and roughly 1000 rows. I need to find out how many times certain combinations of columns can be found within the data set.
In my example below, columns A:B represents the raw data set. In C2 I have a formula that finds all non-unique combinations from columns A:B. What I need is a formula that counts how many times combinations in columns C:D are found within columns A:B. The desired output should be in ColE.
you can do it all in one go... delete columns C, D, E and use this formula:
=ARRAYFORMULA(QUERY({A2:B, A2:A&B2:B},
"select Col1,Col2,count(Col3)
where Col1 is not null
group by Col1,Col2
order by count(Col3) desc
label count(Col3)''"))
for a selected combination only use this formula in E2 cell:
=ARRAYFORMULA(IFERROR(VLOOKUP(C2:C&D2:D, QUERY({A2:A&B2:B},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''"), 2, 0)))
It's always better to share a copy of your spreadsheet, but try entering in E1
={"Count"; ArrayFormula(IF(LEN(C2:C), VLOOKUP(C2:C&D2:D, query({A2:A&B2:B, A2:B}, "Select Col1, count(Col3) where Col1 <>'' group by Col1"), 2, 0),))}
and see if that works?
Note that you can create the same output (columns C, D and E) with a single formula
=query(ArrayFormula(query({A2:B, A2:A&B2:B}, "Select Col1, Col2, count(Col3) where Col1 <>'' group by Col1, Col2")), "where Col3 >1 label Col1 'Value 1', Col2 'Value 2'")

Resources