I'm doing this query at my google spreadsheet:
=QUERY(H4:L35;"select sum(L) where H='First Week'"; -1)
But it returns a little table with "sum" as header and result below it. What I want is just the result! How I remove header? Can I?
Try this:
=QUERY(H4:L35,"select sum(L) where H='First Week' label sum(L) ''")
=QUERY(QUERY(A1:D, "SELECT *", 1), "SELECT * OFFSET 1", 0)
The outer query: "SELECT * OFFSET 1" excludes the first row (the header).
The inner query explicitly specifies one row of headers (via the third argument supplied to QUERY), whilst the outer query specifies none.
=INDEX(QUERY(H4:L35;"select sum(L) where H='First Week'"; -1),2,1)
This just parses the returned array and selects the 2nd record returned in the first column.
You can also do this with the filter function which is less compute intensive.
=SUM(FILTER(L4:L35, H4:H35 = "First Week"))
I have a QUERY which is returning the top 3. I could not get this to work when returning multiple rows. I ended up just hiding the row with the formula and only the answers show now.
For queries using pivot, try using INDEX to remove headers from the pivoted columns.
=INDEX(QUERY('Class hours'!A2:C11,
"select sum(C)
where A = '"&A5&"'
group by A
pivot B"), 2)
Got the answer from this thread:
https://stackoverflow.com/a/63468791/5424088
... or this
=QUERY(QUERY(H4:L35;"select sum(L) where H='First Week'"),"OFFSET 1",0)
This is more concise when ALL label classes are not wanted.
Note that 'select' and 'where' classes are not required in the second QUERY statement.
Instead of labeling column names as blanks using '', you can omit all headers like this:
=QUERY(H4:L35,"select sum(L) where H='First Week'", 0)
See the format here.
Example:
=QUERY(B4:C38,
"SELECT C, sum(B) where C!='' group by C label C 'Member', sum(B) 'Sum'"
)
Related
Right now I am using this query to search for a row based on its Column 1 value. Then it takes the value from the last column. I need a way for it to automatically find the last column in the row since some of the rows have more columns than others.
This is what I had before, which I had manually specified the last column with a value:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select Col10 where Col1 = '5531001'",1)
I have tried using LOOKUP with ARRAYFORMULA I couldn't get it to work:
=QUERY(IMPORTRANGE("link_redacted","PriceList!A1:AZ100000"), "Select (LOOKUP(1, ARRAYFORMULA(1/[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']<>"")[Select Col1 where Col1 = '5531006']:[Select Col100 where Col1 = '5531006']))",1)
Any ideas for a simpler way to do this?
Since no example is presented, I tested the formulas given but no source data is fetched.
so i created a a minimal, reproducible example
Example is the data on the left
Use this formula to get the last non empty columns values.
=ArrayFormula(IFERROR( REGEXEXTRACT( TRIM(TRANSPOSE(QUERY(TRANSPOSE(C3:E),,ROW(C3:E)))), "[^\s]+$")))
Left side is data, right side is expected
How do I combine duplicate rows into one while keeping separate columns?
One way to do that is with query(), like this:
=query( A3:H, "select A, max(B), max(C), max(D), max(E), max(F), max(G), max(H) where A is not null group by A", 0 )
use flatten function with query like this
=UNIQUE({QUERY( FLATTEN(a1:H),"Select * Where Col1 is not null ")})
if you don't want unique just remove unique from this
I have searched on a lot of pages but I cannot find a solution to my problem except in reverse order. I have simplified what I do, but I have a query that comes looking for information in my data sheet. Here there are 3 columns, the date, the amount and the source.
I would like, with a query function, to be able to make different columns which counts the information of column C based on the values of its cells per month, like this
I'm okay with the start of the formula
=QUERY(A2:C,"select month(A)+1, sum(B), count(C) where A is not null group by month(A)+1")
But as soon as I try a little different things by putting 2 query together in an arrayformula, obviously the row count doesn't match as some minus are 0 for some sources.
Do you have a solution for what I'm trying to do? Thank you in advance :)
Solution:
It's not possible in Google Query Language to have a single query statement that has one result grouped by one column and another result grouped by another.
The first two columns can be like this:
=QUERY(A2:C,"select month(A)+1, sum(B) where A is not null group by month(A)+1 label month(A)+1 'Month', sum(B) 'Amount'")
To create the column labels for the succeeding columns, use in the first row, in my example, I1:
=TRANSPOSE(UNIQUE(C2:C))
Then from cell I2, enter this:
=COUNTIFS(arrayformula(month($A$2:$A)),$G2,$C$2:$C,I$1)
Then drag horizontally and vertically to apply to the entire table.
Results:
try:
=INDEX({
QUERY({MONTH(A2:A), B2:C},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label Col1'month',sum(Col2)'amount'"),
QUERY({MONTH(A2:A), B2:C, C2:C},
"select count(Col3) where Col2 is not null group by Col1 pivot Col4")})
I currently have a SUMIF statement that outputs a graph, based upon the value of a dropdown.
=SUMIF('Rev Tracking'!$C$16:$C$57,$E$21,'Rev Tracking'!I$16:I$57)
This creates a sum of all the values in I$16:I$57 where the value of $E$21 is found in $C$16:$C$57.
I'm looking to select from multiple ranges of cells dependent upon the dropdown result, but I'm not sure you can nest SUMIFS inside an IF statement.. i.e.
=if(E21="Client1",(SUMIF('Rev Tracking'!$C$65:$C$76,$E$21,'Rev Tracking'!I$65:I$76)),(SUMIF('Rev Tracking'!$C$85:$C$100,$E$21,'Rev Tracking'!I$85:I$100)))
This doesn't work and feels like it should be quite different.
Any ideas?
Try nested =QUERY() inside an IF statement.
E.g.
=IF($E$21 = "Client1",
QUERY(<<CELL_RANGE_HERE>>, "SELECT SUM(Col1) WHERE col1 = '''&$E$21&''' ", 1),
IF($E$21 = "Client2",
QUERY(<<CELL_RANGE_HERE>>, "SELECT SUM(Col1) WHERE col1 = '''&$E$21&''' ", 1), ... ))
I've found this to be helpful when trying to sum different ranges.
Both of these are reading right so I have the link and the sheet and all the info correct, it's just outputting a little strange. I believe it's the same issue on both of them. Any help much appreciated.
1st issue:
=query(importrange("link","b9:d1000"),"Select Col3 where Col1 = '"&C4&"' ")
When I do this one it needs two rows. It puts the value I want in the first one and leaves the second row blank. As in, if I put anything in the second row, it gives me #REF can't overwrite that cell.
2nd issue:
=query(importrange("link","b9:d1000"),"Select max(Col3) where Col1 = '"&C4&"' ")
When I do this one It gives me two rows: the word "max" and then below it the actual max value. How do I get it to give me just the max value
These are different issues. In the first, there happen to be two rows that meet the condition in where; the second of them has empty Col3. If you want only one result, either revise the where condition by adding some additional requirement, or put limit 1 at the end of query string, to make sure only one row is returned.
"Select Col3 where Col1 = '"&C4&"' limit 1"
Second issue: "max" is the name given to the output column. This name can be changed to empty string with label max(Col3) '', which will eliminate the cell with the name.
"Select max(Col3) where Col1 = '"&C4&"' label max(Col3) ''"