Search code examples
google-sheetsgoogle-sheets-macros

Query Function Order by problem Google Sheets


I already have the first part of the query ready, But I would like to order it with the newest date first. Can you please help!

=QUERY(Sheet3!A:I, "
SELECT D, -1 * SUM(I)
  GROUP BY D
  LABEL -1 * SUM(I) 'Balance Diario'
  FORMAT D         'yyyy-MMM-dd',
        -1 * SUM(I) '$#,##0.00'
")

Solution

  • Is this were you looking for?

    =QUERY(Sheet3!A:I, "
    SELECT D, -1 * SUM(I)
      GROUP BY D
      ORDER BY D DESC
      LABEL -1 * SUM(I) 'Balance Diario'
      FORMAT D          'yyyy-MMM-dd',
            -1 * SUM(I) '$#,##0.00'
    ")
    

    Put more ORDER BY D ASCorDESC

    DESC is to reverse the order