How to Query Data in Google Sheets
Use the built in SQL-like Query Language

Search for a command to run...
Use the built in SQL-like Query Language

No comments yet. Be the first to comment.
Two ways to make pop-up images in a Google Sheet

Since last we spoke I’ve been recording several new long and short form videos. Check out the YouTube Channel if you haven’t. I’ve also wrapped up training for a marathon I’ll be racing on March 3rd… 🤞🤞 Now to the sheets… Do you ever feel lost in E...

Originally published for freeCodeCamp In this article I will show you how to allow for multiple items to be selected using the drop-down data validation feature in Google Sheets. Here's the Google Sheet we'll use for the example. You can make a copy...

Originally published for freeCodeCamp Without clean data, your spreadsheet is knocking on death's door. In this tutorial, I will show you two fast ways to clean up the data in your Excel or Google Sheets spreadsheet. When dealing with data sets, esp...

Originally published for freeCodeCamp In this article I will show you how to format cells in Microsoft Excel. We'll be looking particularly at the Accounting format for cells with numbers. At the end of the article I'll give you two bonuses: a short...

This article appeared first on freeCodeCamp's news publication.
I built a spreadsheet and wanted to display some of the data in a small table which would update based on the day of the week.
After some digging, querying seemed the best option to pull this off.
In this article, you'll learn several things about Google Sheets tables, functions, queries, data validation and formatting including:
Google Sheets indeed has a built in "Google Visualization API Query Language". Check out the docs here.
Some of the syntax is the same and much of the functionality is similar to SQL, so you should pick it up quickly if you are familiar with SQL at all.
I know but a little when it comes to SQL, but I was able to parse my way through some basic queries with little trouble.
In fact, the thing that gave me the most trouble was cell referencing syntax. And I hope this post can save you some head scratching that I went through today.

First things first: get all the data in a well organized table. This is sometimes the hardest part of any data analysis: simply getting the data in an orderly, usable format.

I used data validation for the days of the week to ensure I didn't have a typo in there since our query will depend on those days.

Select the entire table to create a named range. This will make things cleaner and easier in the next step. It's good practice to keep data as tidy as possible.

Confirm and name the range to save it.

Now, let's make another sheet to put our query into. I only need two columns for our data: one for the person and one for the task. Make room for more if your data requires it.
The first step requires a little trick to make the current day display when the sheet is loaded and for this to be used in our query.
There is a built-in =Today() function, but using it alone is not enough even when you change the formatting. They query won't recognize it as matching the days of the week text in our table.
Instead, wrap the Today() function inside the Text() function as shown below. The Text() function accepts a number and a format as arguments. When we pass it Today(), it can convert that date number into text using the format "dddd". Neat, right? 😊

In Google Sheets, =QUERY is also a built in function. As you type it in the cell (B22 in my example) you can click the drop down arrow in the top right to get more information on the parameters accepted.

We'll select our data. Type the name of the range you created and it will automatically select that table.

You can manually select the range for the table to query if you choose. But you want to be as awesome as possible, so use that named range! 🙌
We want to select and return the first two columns (the names and tasks) in our data sheet based on the fourth column (the day of the week).
The query reads =QUERY(heat,"select B,C where D='"&B21&"'",1).
And yes, that nastiness with the single quotes, double quotes and ampersands is necessary for the conditional statement we are creating.
We're telling the query to match the D column in our data sheet with the value in B21 which is now text thanks to our previous formula manipulating the day of the week.
The syntax to match the text in the cell is gross, but it's just how you have to do it.

That last parameter 1) is letting the query know that there is one row of headers to display (name, task).
And, voilà! We've got ourselves an automatically updating task list based on the current day of the week. All that's left is cleaning up the final result! 🎁

##Official Examples
I referenced this article from the QUERY function page on Google Support to learn, and it has a Google Sheet you can copy with a bunch of examples in it. Super helpful.

Here is the sheet I built for this article. You are free to make a copy of it and use yourself.

I write about web design and development from a solopreneur's perspective at https://blog.eamonncottrell.com/ and you can find me on Twitter: https://twitter.com/EamonnCottrell
Have a great one! 🎉
