Member-only story

Dynamic drop-down values for PowerApps

bluehoodie
3 min readJan 5, 2021

--

One of the most common questions when building PowerApps form is how can we dynamically change the value in a dropdown box when a user selects an option. This happens most often when we are designing forms that require country and state fields. In this article, we are going to create a simple dynamic/cascading dropdown, where the state values change based on the country selection.

Dynamic Drop-Down List

Create two drop-down boxes and labels as shown above. For the first drop-down box, under the Items property, input

[“Cyprus”, “Hong Kong”]

In the second drop-down box, include this code in the Items property

If(Dropdown1.Selected.Value = “Cyprus”, [“Famagusta”, “Kyrenia”, “Larnaca”, “Limassol”, “Nicosia”, “Paphos”], [“”])
Adding if-else in the State Dropdown Items property

Now, when you select “Cyprus” in your country drop-down, your state value should change accordingly.

However, in most country and state drop-down fields, it would be time-consuming to write a list for every single country and an if-else for every different country. We need a better way to manage, thus, we are going to create a collection to store country and states. Collections are a way to store data in your app. Think of it as a table that is stored within your application.

Add a collection to your app using the OnStart property in the App. This allows the table to load when your application starts. We are going to create a simple country, state table called countryTable. Input the code below in the OnStart property

ClearCollect(countryTable, 
{country: “Cyprus”, state: “Famagusta”},
{country: “Cyprus”, state: “Kyrenia”},
{country: “Cyprus”, state: “Larnaca”},
{country: “Cyprus”, state: “Limassol”},
{country: “Cyprus”, state: “Nicosia”},
{country: “Cyprus”, state: “Paphos”},
{country: “Hong Kong”, state: “ “},
{country: “Georgia”, state: “”})
Adding a collection in the App’s OnStart Property

--

--

bluehoodie
bluehoodie

Written by bluehoodie

Time hacking at work with modern workplace tools

No responses yet

Write a response