I have a data table where I enter all my expenses and incomes.
I would like to group them using the query.
M 1000 income 12/02/2023
b 2000 income 12/03/2023
a -400 spending 22/03/2023
d 2000 income 14/01/2023
b -300 spending 12/01/2023
a 1000 income 12/08/2023
The query so far looks like this :
=QUERY(A1:B6;"select A, sum(B), count(B) group by A";)
The issue I have is that I would like to sort the query by date (from the first occurence, for exemple b would be first in row, followed by d then M then a.)
Is there a way I can do that?
https://docs.google.com/spreadsheets/d/13FgeEmMcbiZf_VKRsQ2NzCS9yc8316qNJT6cRl5x_y4/edit?usp=sharing
>Solution :
Within QUERY you could use MIN(D) to find the "smallest" date and sort the range by it:
=QUERY(A1:D;"select A, sum(B), count(B),MIN(D) where A is not null group by A order by MIN(D)";)
If you want, you can wrap it in another QUERY to get rid of that extra column:
=QUERY(QUERY(A1:D;"select A, sum(B), count(B),MIN(D) where A is not null group by A order by MIN(D)";);
"Select Col1,Col2,Col3")
