Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort pie chart's slices without sorting the data in the columns

I haven't found something similar to that on the web, and it seems that the only way for the data to be sorted on the pie chart is if they're pre-sorted. The problem is that I have a sheet populated by a third party software (Typeform) that places random data, which I then aggregate to present to the pie chart.

More specifically, Typeform writes

 town   | salary | cost
London  | 1000   | 500
Bristol | 700    | 300
London  | 900    | 400
Leeds   | 600    | 200
Leeds   | 500    | 300
Leeds   | 400    | 200

Then I aggregate the data in another sheet (Sheet2) so that I have

town   |  occurrences
London      2
Bristol     1
Leeds       3

Obviously the pie chart will draw London first, then Bristol, and then Leeds. These are only 3 entries, however in my example, I have 20, and the data in the pie chart are not ordered.

Sheet2's data cannot be sorted descending since I am using =UNIQUE(Sheet1!A2:A) and then in the column next to it =countif(Sheet1!A:A,A2) to populate them from the Sheet1 where the 3rd party software is writing them, in fact when I select them and click sort they don't get sorted, they reappear as they were.

Is there any way to sort them (and keep them sorted) in Sheet2, or by writing them in a new sheet?

like image 291
dqm Avatar asked Nov 08 '15 18:11

dqm


1 Answers

If town is in A1 of Sheet1 please try:

=query(Sheet1!A2:D7, "select A, count(C) group by A")  

SO33597438 first example

SO33597438 second example

like image 90
pnuts Avatar answered Oct 13 '22 05:10

pnuts