Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query data in google spreadsheet and format resulting columns

       A        B      C      D       E     F      G       H          I       
   +--------+------+-------+------+-------+---+---------+------+--------------+
 1 | Select | Name | Price | URL  | Desc  | - | Select  | Name | Price(13.97) |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 2 | x      | n2   | 4.99  | url2 | desc2 | - | x       | n2   | 4.99         |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 3 |        | n3   | 3.99  | url3 | desc3 | - | x       | n6   | 3.99         |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 4 |        | n4   | 7.99  | url4 | desc4 | - | x       | n9   | 4.99         |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 5 |        | n5   | 4.99  | url5 | desc5 | - |         |      |              |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 6 | x      | n6   | 3.99  | url6 | desc6 | - |         |      |              |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 7 |        | n7   | 4.99  | url7 | desc7 | - |         |      |              |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 8 |        | n8   | 3.49  | url8 | desc8 | - |         |      |              |
   +--------+------+-------+------+-------+---+---------+------+--------------+
 9 | x      | n9   | 4.99  | url9 | desc9 | - |         |      |              |
   +--------+------+-------+------+-------+---+---------+------+--------------+

Given the table above A1:E9, I want to generate the result shown in columns G:I

I succeeded getting a similar result (without the parethesis and their value in I1) using in G1 this formula:

=Query(A:E, "SELECT A, B, C WHERE A CONTAINS 'x' ORDER BY B ASC",1)

The question is: How to add the sum of the selected rows to the header of the last column as shown in the example?

Thank you in advance :)

like image 514
Enissay Avatar asked Mar 27 '14 15:03

Enissay


People also ask

How do I QUERY data in Google Sheets?

The format of a typical QUERY function is similar to SQL and brings the power of database searches to Google Sheets. The format of a formula that uses the QUERY function is =QUERY(data, query, headers) . You replace “data” with your cell range (for example, “A2:D12” or “A:D”), and “query” with your search query.


1 Answers

You can break it up into separate parts instead of trying to do it in one query.

In cell G2, use the query:

=Query(A:E, "SELECT A, B, C WHERE A CONTAINS 'x' ORDER BY B ASC label A '', B '', C '' ", 1)

This returns the query without column headers, then you can simply fill in the "name" and "select" column headers into G1 and H1 manually. Then for the cell I1 use

=CONCATENATE("Price (", SUM(I2:I), ")")
like image 150
capturesteve Avatar answered Sep 22 '22 14:09

capturesteve