AdWords Scripts. report ORDER BY not working

1.2k Views Asked by At

This function suppose to show in which hours adverts are clicked more often. It works fine however I have problem with sorting it by "HourOfDay". When I add ORDER BY HourOfDay to the end of the query I get en error.

function exportReportToSpreadsheet() {
  var spreadsheet = SpreadsheetApp.create('INSERT_REPORT_NAME_HERE');

  var report = AdWordsApp.report("SELECT Clicks, Impressions, AverageCpc, HourOfDay FROM ACCOUNT_PERFORMANCE_REPORT DURING LAST_MONTH ORDER BY HourOfDay");

  report.exportToSheet(spreadsheet.getActiveSheet());
  Logger.log("Report available at " + spreadsheet.getUrl());
 }

exportReportToSpreadsheet();

Anyone knows what is wrong with ORDER BY in AdWordsApp.report ? https://developers.google.com/adwords/scripts/docs/reference/adwordsapp/adwordsapp_report According to AWQL query language documentation it should work as expected. https://developers.google.com/adwords/api/docs/guides/awql#using_awql_with_reports

BUG?

1

There are 1 best solutions below

0
On

You cannot sort reports. From the AWQL documentation:

ORDER BY and LIMIT (sorting and paging) are NOT supported for reports. Including these clauses in a query will generate an error.

Ordering is only possible when you use the different entities` selectors, e.g. to iterate over campaigns sorted by cost you could do

campaignIterator = AdWordsApp
    .campaigns()
    .forDateRange("LAST_MONTH")
    .orderBy("Clicks DESC");