Search code examples
google-cloud-platformlooker-studio

How to sort diseases in descending order for Looker Studio table from Google Sheet columns


I have a Google Sheet that looks like this:

Asthma Urinary Tract Infections
1 1
1 1
1
1
1 1
1 1
1
1 1

There are around 50 or so diseases in the above format, the 1 represent positive case on a certain date (kindly refer to google sheet.) I want to display the sum of every disease in descending order. Expected outcome given below.

Diseases Count
Acute (upper) respiratory infections 4000
Chronic Obstructive Pulmonary Diseases 3454
Asthama 2300
Sexually Transmitted Diseases 1200

Basically I want a top 10-15 of diseases. I've been trying to make it work somehow but I can't get the diseases to appear row wise. An editable report is given below. https://lookerstudio.google.com/reporting/ea611a8e-a6b7-4dd7-96bd-21c17149e1c6 Any help would be appreciated. Thank you.


Solution

  • Here's one (alternate)approach you may try out; this requires restructuring (de-pivoting) your raw_data into the style as in screenshot. the below sheets formula does the heavy lifting to transform the data in one-go & also accounts for any new data you may add to the original raw data tab in the sheet

    =let(rep_,Sheet1!A2:C, grp_,Sheet1!D2:CB, header_,Sheet1!D1:CB1, size_,1,
         Σ,reduce(wraprows(,columns(rep_)+1+size_,),sequence(columns(grp_)/size_,1,1,size_),lambda(a,c,{a;{rep_,wrapcols(index(header_,c),rows(rep_),index(header_,c)),choosecols(grp_,sequence(size_,1,c))}})),
         filter(Σ,index(Σ,,column(grp_)+1)<>"",--index(Σ,,column(grp_)+1)))
    

    enter image description here