Referencing Query Data
Once you have executed the query (see Extracting Data from a Query), you can access specific ranges of the query result set. The data-referencing syntax allows you to also group and filter the results, and to create expressions.
Referencing a Query Column
You can reference all cells of a field (column) in the result set by using the field name:
q['state'];
The following example illustrates this approach.
Consider the sample 'customers' query. In this example, you will extract all the values under the 'state' column and use them to populate a formula table. Follow the steps below.
1. Create a new report. Add a table with two rows and four columns.
2. Run the 'customers' query in the onLoad script. (See Extracting Data from a Query for more details.) var q = runQuery('customers')
3. Select cell[1,0]. Right-click on the cell and select 'Format' from the context menu. This opens the Format panel at the bottom.
4. Click the Data tab in the 'Format' panel. Select the 'Formula' button in the 'Binding' section, and enter the following formula for cell[1,0]: q['state'] This will extract the entire 'state' column from the 'customers' query to populate the table.
5. In the 'Expansion' region of the Data tab, select 'Expand Cell' and choose 'Vertical'. (This causes the extracted data to fill down vertically.)
6. Preview the report and see how the table is populated with all of the records from the 'state' column.