Monday, 13 February 2017

The Google Sheets' QUERY formula is a powerful way to analyze your Xero Accounting data with SQL like commands

Google Sheets has a fantastic built in SQL-like Query function that, when combined with Blink Reports, can instantly answer questions like; what are my total sales by Customer?

The syntax is:
QUERY(data, query, [headers])
The documentation is available at: https://support.google.com/docs/answer/3093343

You can see live examples by opening our Blink Reports Template and clicking on the "XeroInv Query" tab/sheet.

A simple example that calculates total sales by Contact (Customer) based on the output of the Blink Reports custom formula XeroInv() is:
=query(XeroInv!$A$11:$AF$999,"select B, sum(I) group by B",-1)
or expand it to exclude blank rows and use your own column labels:
=query(XeroInv!$A$11:$AF$999,"select B, sum(I) where B != '' group by B label B 'Customer', sum(I) 'Total Sales'",-1)
  • XeroInv!$A$11:$AF$999 is the location of the data in the spreadsheet which in this case is the results of the XeroInv() formula on the sheet named XeroInv
  • "select B, sum(I) where B != '' group by B label B 'Customer', sum(I) 'Total Sales'" is the actual query using Google Visualization API Query Language which is similar to SQL.
  • In this example it outputs the Contact from column B and then calculates the sum by Contact of column I.
  • where B != ''  filters out blank contact records
  • label B 'Customer', sum(I) 'Total Sales' provides more friendly column names
  • -1 means output 1 or more rows of headers depending on the source data
This formula will produce the output:
CustomerTotal Sales
Bank West1299
Basket Case914.55
Bayside Club234
Boom FM1623.75
City Agency593.23
City Limousines1191.83
DIISR - Small Business Services1077.14
Hamilton Smith Ltd2173.75
Marine Systems396
Petrie McLoud Watson & Associates1407.25
Port & Philip Freight1082.5
Rex Media Group1632.5
Ridgeway University12375
Young Bros Transport1082.5

You can also produce pivot tables such as total Sales by customer but split by invoice status across the columns:
=query(XeroInv!$A$11:$AF$999,"select B,sum(I) where B != '' group by B pivot E label B 'Customer',sum(I) 'Total Sales' ",-1)
Which produces a pivot table:
CustomerAUTHORISED Total SalesPAID Total Sales
Bank West1299
Basket Case914.55
Bayside Club234
Boom FM1623.75
City Agency593.23
City Limousines1191.83
DIISR - Small Business Services838.94238.2
Hamilton Smith Ltd5501623.75
Marine Systems396
Petrie McLoud Watson & Associates1407.25
Port & Philip Freight1082.5
Rex Media Group5501082.5
Ridgeway University6187.56187.5
Young Bros Transport1082.5
Unlike Microsoft Excel, this query formula is built in so there are no software plugins or addons to install and keep up to date. Google Sheets make sharing and collaborating on these reports with your team as simple as sending them a web page link since they only need a web browser to view them.

The query formula combined with Blink Reports offers endless possibilities for slicing and dicing your sales or purchase transaction data from your Xero Accounting Software.

Sign up today for a Blink Report free trial at http://www.blinkreports.com/