Avoid auto sorting in Google Sheets Query

Viewed 43

I am facing the issue, that during a query I get auto sorting of the group of results. The code is following: =QUERY('Sheet1'!A1:H;"select A, sum(H) where A is not null group by A ";1)

I would like to keep the original order of elements and not want to get a sorted list.

I would appreciate any help in this topic.

Thank you in advance.

2 Answers

An easier way is this. You can use Filter, Unique and Sumif.

={unique(filter(DB!A:A,DB!A:A<>"")),arrayformula(SUMIF(DB!A:A,unique(filter(DB!A:A,DB!A:A<>"")),DB!H:H))}

Ciao @Terio

In my video I learn how these functions are used with SUMIF. But it's in Italian : https://youtu.be/aEMrczLlwrE

This do what you want

=ARRAYFORMULA({FILTER(UNIQUE('PH1'!A1:A);UNIQUE('PH1'!A1:A)<>"")\ARRAY_CONSTRAIN(SUMIF('PH1'!A1:A;UNIQUE('PH1'!A1:A);'PH1'!H1:H);ROWS(FILTER(UNIQUE('PH1'!A1:A);UNIQUE('PH1'!A1:A)<>""));1)})

maybe I can simplify them, but work and not apply a sort to A, ask for more if you need

Related