Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Google spreadsheets How to get the output of CASE functionality in sql

Below I have given a dataset and expected output on google sheets. In a normal database, my query would have been Select industry, CASE WHEN change > 0 THEN count(ticker) END) as change, etc. How do I get the expected shown in the picture

enter image description here

I tried multiple Querys, arrayformula and several other functions, none of them has giving all the 3 columns

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here you have an option. First it finds the unique values from industries, and then uses them in BYROW. Inside BYROW, it lists three values: each which is the name, the first COUNTIFS that finds the positive values, and the COUNTIF that counts all the occurences of the industry:

=LET(indus,TOCOL(UNIQUE(B2:B),1),
BYROW(indus,LAMBDA(each,
{each,COUNTIFS(C2:C,">0",B2:B,each),COUNTIF(B2:B,each)})))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading