Use column names in your Google Spreadsheets QUERY() functions. This script is based on this YouTube tutorial.
Script ID: 1BZyZAV5h_cgqvMh0oU86PiKC_GK6yMPPk74eDmQjZ2Ijrhm-si3BwUxd
=QUERY(A1:H, SELECT("SELECT SUM([amount]) WHERE [amount] > 0 LABEL SUM([amount]) ''", 'A1:Z1), 0)
SELECT expects 2 parameters:
- Your query
- Range of the column names (should be exactly one row)
Each column name (= placeholder) needs to be surrounded with [ ] and can be targeted
with the camelCase version of the names in the "header row":
| Column name | camelCase field |
|---|---|
| id | [id] |
| Purchased On | [purchasedOn] |
| Amount | [amount] |
The 'SELECT` function is made available as a script library. Follow these steps to add it to your project.