cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JRaasumaa
Memorable Member
Memorable Member

Dropdown list with distinct values and option for "All"

I wanted to share this technique I've been using to create a dropdown from a datasource as well as include an option for "All"

 

There are 3 steps, 1st collect the word "All" into your dropdown list named collection with ClearCollect

 

 

ClearCollect(DropList, {Result:"All"})

Make sure to collect the word "All" in a column "Result" (this is important to name it Result)

 

 

2nd, Use a regular Collect of the data source's distinct values. I typically filter the data as well as sort.

 

 

Collect(DropList, Sort(Distinct(Filter('DatasourceHere',Project <> ""),Project),Result,Ascending))

This collection does a few things, it filters out the DataSourceHere by something, in this case items without a blank string.It also gathers only distinct values, in this case distinct Project column values. Then last it sorts the filtered data set by a column, because it's a Distinct filter of the data the column it creates is named "Result", and that's what it is sorting Ascending by.

 

 

 

3rd, put the DropList name in the dropdown as it's item's property.

 

 

You will want to combine these in a way the list can be loaded on screen visible property or with a button press etc. I always put these two items back to back.

 

ClearCollect(DropList, {Result:"All"});Collect(DropList, Sort(Distinct(Filter('DatasourceHere',Project <> ""),Project),Result,Ascending))

 

By doing this you can use the "Results" column to build a dynamic dropdown list with unique sorted values from a datasource as well as have an option "All" at the top of the dropdown giving the end user a great filtering or sorting tool!

 

 

Let me know if anyone has questions, hopefully this is helpful.

 

 

3 REPLIES 3
v-micsh-msft
Community Support
Community Support

Thanks for the sharing!

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
mx
Advocate III
Advocate III

cool. Logged and noted.

 

DatabaseMX ('mx')
Microsoft Access MVP
jesenavaranjan
Helper V
Helper V

ClearCollect(DList, {Result:"All"});Collect(DList, Sort(Distinct('[dbo].[tbOrgStructure]',D),Ascending)) I'm doing this in my On Start for the App but my app is showing empty values.

 

Any ideas why?

Please and thank you

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,099)