Home > Software design >  Can I sort output of QUERY and include labels?
Can I sort output of QUERY and include labels?

Time:10-26

I'm trying to format my budget spreadsheet which updates automatically with an attached form. ColA is hidden since it's a timestamp, ColB is the date that the purchase was made, ColC is the category, and ColD is the amount.

I'm trying to sum all amounts within a category and have the output (in ColD) be sorted in descending order, as well as output the labels next to the amounts (in ColC). I have tried using SUMIF, but it's frustrating to use when I want to add multiple categories in specific ranges together. Here's the current code I'm using:

=QUERY(C3:D64, "SELECT SUM(D) WHERE C <> 'Income' GROUP BY C LABEL SUM(D)''")

This outputs my data, but without the labels and not in descending order. I can make the order descend in ColE with this code, but again, not labeled:

=QUERY(D65:D72, "SELECT D ORDER BY D")

Is there a way to simplify my code and have it output with labels in descending order, including labels for amounts where the output is 0? Here's a screenshot of my current setup. Spreadsheet screenshot

CodePudding user response:

You can add labels anyway, but make sure you keep proper order. 1 SELECT 2 WHERE 3 GROUP BY 4 ORDER BY 5 LABEL (full list of commands is available in [documentation]: enter image description here

  • Related