Domanda

I'm trying to build a report in Google Spreadsheets using the query() function. I want to select the average date difference using the dateDiff() and avg() functions.

Here is my query:

select avg(dateDiff(A, B))

And here is the table I'm trying to select from:

+---------------------+---------------------+
|          A          |           B         |
+---------------------+---------------------+
| 01/08/2013 15:41:00 | 31/07/2013 13:35:00 |
+---------------------+---------------------+
| 31/07/2013 17:17:00 | 31/07/2013 09:57:00 |
+---------------------+---------------------+
| 06/08/2013 15:14:00 | 29/07/2013 13:50:00 |
+---------------------+---------------------+

And this is the error message I get:

error: Invalid query: Query parse error: Encountered " "(" "( "" at line 1, column 20. Was expecting: ")" ...

Here is an open copy of the spreadsheet I've been working on. https://docs.google.com/spreadsheet/ccc?key=0AhEoOqMhLAGbdEE1ZkhqSjlDT0lYVnVhY3hjNmlWZ3c#gid=0

Is it even possible to do with using the query() function?

È stato utile?

Soluzione

If I'm understanding correctly, you require a single average of all the date differences. In which case it would be best to use the AVERAGE spreadsheet function outside the QUERY function.

=AVERAGE(QUERY(A1:B3;"select datediff(A,B) label datediff(A,B) ''"))

It actually isn't really necessary to put the label datediff(A,B) '' as the AVERAGE function will ignore the text header populated by the QUERY, but I put it in for the sake of completeness.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top