Previously, I would query a google sheet using the Google Visualization API. I've been working on converting my Google Chart to use Google Apps Script because of authentication issues. How can I do a GROUP BY query to send to my Google Chart using Google Apps Script?
Old Way (Google Visualization API)
function getCurrentData() {
URL = 'https://docs.google.com/spreadsheets/d/SHEET_ID/gviz/tq?gid=2017811003&headers=1';
var query = new google.visualization.Query(URL);
var queryString = 'SELECT A, B, C GROUP BY A, B';
query.setQuery(queryString);
query.send(drawChartFunct);
}
New Way (Google Apps Script)
function getCurrentData() {
var ssID = "SHEET_ID",
sheet = SpreadsheetApp.openById(ssID).getSheets()[2],
data = sheet.getRange("A1:C13").getValues()
??Query_Code??
return data;
}
var result = Utils.gvizQuery(ss.getId(), "SELECT A, B, C, D, E", 0, 0);will return[[null, null, null, null, null], [Date(2017,4,1), 120145, 28750, 12555, 161450],...]The header is not captured correctly. - Clarkus978var result = Utils.gvizQuery(ss.getId(), "SELECT A, B, C, D, E", 0, 1);Note: you'll get back an array of objects, where each object has properties whose keys are the headers. - TheAddonDepot