简体   繁体   中英

Google Sheets QUERY: unexpected empty result in the output

I'm struggling with a query displaying no result in the output. Here is the editable file: https://docs.google.com/spreadsheets/d/1qLobNYV7TXc-ZtJuEVy-AjODzIKLKNUvD6Gb9ycZgFc/edit?usp=sharing

In the data2 sheet, column G, I have this formula in G3 (no result found):

=QUERY(data!$A$1:$O$7122; "SELECT avg(M) WHERE B = '"&$G$1&"' AND E = '"&A3&"' label avg(M) ''";1)

The same formula (except the added WHERE clause on the year) is working in B3. You can see in the data sheet that there is data with the year 2018.

Any idea why it's not working?

Thank you so much for you help!!

Don't use the single quotes around numbers. So

WHERE B = '"&$G$1&"'

should be

WHERE B = "&$G$1&"

To limit the number of queries in your sheet, I provided you with an alternative solution that outputs the results per year with a single formula (per year). In M3 you'll find

=ArrayFormula(If(len($A$3:$A); iferror(vlookup($A$3:$A; QUERY(data!$A$1:$O$7122; "SELECT E, avg(M) WHERE B = "&M$1&" group by E label avg(M) ''";1); 2; 0));))

This formula was then dragged to the right.

I hope that helps?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM