In this post we’ll discuss how to conditionally, display values from multiple columns/sources inside a single drop down/combo box control in Microsoft PowerApps.
We all know that how easily we can bind data to a drop down control in PowerApps. Basically, we just need to point the right column of the data source to the drop down control and, all the values gets loaded automatically.
In this case, however, we’ll be populating the drop down control from a SharePoint master list. This list contains 2 columns, SiteName and FriendlyName.
The requirement is that, to show the values from the column, FriendlyName, only if it is not empty. Otherwise, show values from the column SiteName.
For ex, based on the above picture, my drop down control should display the following,
- About Us
Directly, we cannot bind a single drop down to multiple columns. However, we can create a new column in our PowerApps collection, and then bind the control to this new column.
To do that, we can simply write the following code to the Items property of our drop down or combo box control.
AddColumns(MultipleDataSourceDropdown, "HybridColumn",If(IsBlank(FreindlyName) || IsEmpty(FreindlyName), Title, FreindlyName))
Be sure to set the Value property of your control to this newly created column.
Run the app. The drop down or, combo box will load items from both the sources, conditionally. Similarly, sometimes we might need to append the values of 2 or more columns to display inside the drop down. It can also be achieved using the same approach.
We’re passing the following values to the function, AddColumns.
|MultipleDataSourceDropdown||Source List. This is our data source.|
|HybridColumn||The name of our new column. We can use any value here.|
|[Formula]||This formula will be used to populate the value of the newly created column against each row of the given collection.|
Cascading Drop Down
The approach for loading multiple values based on the selection of another control is equally possible. In the same formula, replace the data source with your cascading query. In cascading, we just eliminate the unwanted data. In this approach we’re not concerned how the data is loaded, directly or via cascading. We’re just adding a new column, irrespective of the data source.
AddColumns(CascadingFilterQuery, "HybridColumn",If(IsBlank(FreindlyName) || IsEmpty(FreindlyName), Title, FreindlyName))
- PowerApps does allow us to manipulate the data, before appending it to any control.
- Data added to a drop down or, combo box is actually a collection. Hence, we can use all the PowerApps functions that can be applied to a collection.
- The sample will also work with cascading controls as well.
- The example shown above is loading the data conditionally from 2 columns. However, the possibilities are endless. We can also choose to combine 2 or more columns to display a unified text.
- The important thing is that, the formula, for the new column, is in our hand and that, we can put any custom operation over there.