Learn how to create dropdown menus that will dynamically populate based on another dropdown menu. Copy our practice sheet to see this concept in action.
What Is A Dynamic Dropdown Menu
The goal of a dynamic dropdown menu is to show only relevant information in subsequent dropdowns. Also, known as dependent dropdowns, because the contents of a menu are dependent upon another dropdown’s selection. There are 2 different techniques to creating a dynamic dropdown menu.
In our practice sheet we create a dynamic dropdown to only show cities that are within a selected state and a dropdown menu for the
CONVERT function. We want to create a dynamic dropdown that will only show relevant variables to the dependent dropdown.
Practice Sheet Scenario
We have created a formula that will find a cities average temperature for any selected month. To help with this user experience we only want to show cities that are in the selected state.
The filter method takes advantage of the
FILTER function. It works great for generating lists with corresponding variables. This means we have a list of data that we can easily filter by a cell in the corresponding column or row.
In our practice sheet you will find a spreadsheet of cities and the state they belong to under the “Data Validation FILTER” tab. The goal of our dynamic dropdown is when a user selects a state the cities dropdown menu will on show cities within that state. For instance, if we select Florida from the state dropdown we will want to show; Jacksonville, Miami, Palm Springs, and Tampa in the cities dropdown menu.
The first step is to set up a data validation for the city select dropdown. We will use “List from a range” criteria. This will allow our data validation to display what ever is the selected range. In our practice sheet you can see we set our range to
'Data Validation FILTER'!D3:D54. This ensures we will always pull all data our filter function extracts.
Next we need to write our
FILTER formula. In
'Data Validation FILTER'!D3 we can add the code as seen below.
=FILTER(B:B,A:A='Dynamic Menu FILTER'!A2)
Our formula states that we would like to filter the data in our cities column. The
A:A='Dynamic Menu FILTER'!A2 is the condition to filter our cities column by. We are stating that we would like to filter column
B if column
A contains our selected state from our dropdown in the “Dynamic Menu” tab.
FILTER function can be expanding by adding additional conditions, this is the simplest way to create a dynamic dropdown. But there are times that the Filter Method is limited if your data you wish to filter doesn’t have corresponding cells.
Practice Sheet Scenario
In our practice sheet we need a dynamic dropdown menu that will convert values from one unit to another, but for the units to be converted they have to be in the same category. For instance, we cannot convert Fahrenheit to Years, because Fahrenheit is a in the Temperature category and Years is in the Time category.
When the category of conversion is selected, we only want to show start units and end units that pertain to that category.
For the start and end unit we will create a dynamic menu using the named ranges method. For the
CONVERT function output we will use the Index Match Method. Both methods will work, it just depends on your preference.
Named Ranges Method
The Named Ranges Method works by naming a specific range and then using the
INDIRECT function to reference the named range. Remember the goal is for a user to be able to select a category (Temperature, Weight, Distance, etc.) and only show units within a category (Time: Second, Minute, Hour, Day, Year) to convert a value from one unit to another.
- First we need to use data validation to create the category dropdown list. We will use the “List from a range” criteria and reference column
Ain the “Data Validation” tab. We now have a dropdown menu of the 13 different conversion categories Google Sheets recognize in their
- We want the starting and ending unit to correspond to the selected category. In the variables tab you can see all acceptable variables the Google Sheets
CONVERTfunction recognizes and in row 1 you can see each category the units belong to. We will create named ranges by selecting the appropriate cells and select Data Named ranges in the menu. We will name each of the different categories the exact same name we used in the data validation in step 1. For example,
Variables!A1:A12range will need to be named Weight, because Weight is the exact spelling of an available category we created in step 1. Review the named categories.
- Now we can utilize the
INDIRECTfunction to pull the named range from the referenced cell. By setting the formula below in cell
B1of the “Data Validation” tab the corresponding named range will appear down column
- The last step is to set our data validation for the starting and ending units in
D2to create a dropdown from a “List from a range”
When we change the category now, the stating unit options change to match the corresponding category.
Index Match Method
The Index Match Method works in a similar way as the
INDIRECT method, but will not require you to make named ranges. The advantage to not needing named ranges is it makes it simple to easily pull specific columns. Since, we will need to extract the variables that correspond to each category (Fahrenheit is “F” in the
CONVERT function). Rather than make an additional 13 named ranges for the unit variables we will use the Index Match Method.
AD in our “Variables” tab we will place this function.
We start by indexing all of the variables. We then don’t set a specific row in the
INDEX function so we will pull an entire column. To extract the correct column location we use the
MATCH function. The match function allows us to match the selected category in
'All Available Conversions'!B2. This is the data validation we setup in step one in the Named Range instructions. We are searching for an exact match for the category (e.g. Weight) in row 1. The 0 means it needs to be an exact match. The reason we are adding a plus one is we want to extract the corresponding variables and not the starting or ending unit name. If we removed the
+1 we would produce the same list we created using the Named Range method.