How to Create a SQL LISTAGG Function with Google Sheets

By: Kirk Olson

Kirk Headshot.jpg

Kirk Olson is a founding member of OneNumber. After many years of working with NCR and HP and starting several of his own smaller companies, Kirk brings a variety of insights to organizations looking to launch new products and overhaul processes. He lives in Seattle and can be found running marathons and cheering on his favorite baseball teams in his downtime.

LISTAGG is a powerful SQL command to denormalize rows data. 

But, what if you don’t have access to SQL or just need a quick way to accomplish this?

 For example, you need to take this table of data:

 
151-1.png
 

And convert it to:

 
151-2.png
 

In SQL, we would use the LISTAGG function like this:

 
151-3.png
 

If you can’t use SQL, here is an easy way to use Google Sheets to accomplish this:

First, find the UNIQUE Site ID values:

=UNIQUE(B2:B)

 
151-4.png
 

Next, join and filter the rows of data using these functions:

=join(",",filter(A:A,B:B=C2))

 
151-5.png
 

That’s it! Here is a link to the spreadsheet.

Curious when you would want to use the LISTAGG function? Check out this blog post about creating a permissions model for Tableau dashboards.

We use Google Sheets’ powerful data manipulation tools for all kinds of quick transformations and for prototyping.  It has SQL-like abilities, we make shorter work of complex data transformations without the need of SQL.

Want help on your own project? Check out our availability on Eventbrite or reach out directly and we can help!

How to Create a Multi-Row Formula in SQL (Because Tableau Can't)

Nested IF Statements in Tableau

0