web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Appending item to Coll...
Power Apps
Answered

Appending item to Collection generated from DISTINCT

(2) ShareShare
ReportReport
Posted on by Microsoft Employee

I want to append an item to a collection that was created using DISTINCT?

ClearCollect(EmployeeList,Distinct(FeatureAccess,EmployeeName));

I want to append "All" to the top of the dropdown list that uses EmployeeList as Items property.

 

Thank you in advance.:)

Categories:
I have the same question (0)
  • Paul_C Profile Picture
    Microsoft Employee on at

    Hi ManishM,

     

    Let me confirm that I understand the problem. You created a collection using ClearCollect(EmployeeList, Distinct(FeatureAccess,EmployeeName)); and now you want to prepend "All" to the top of the list? ClearCollect lets you specify multiple items to add to the list (in order). So, I would recommend you replace your existing ClearCollect with this, if I understand the problem correctly: 

    ClearCollect(EmployeeList, "All", Distinct(FeatureAccess,EmployeeName));

    This will clear EmployeeList, then add "All" to it, then add the Distinct() result.

     

    Hope that helps!

     

  • ManishM Profile Picture
    Microsoft Employee on at

    Thanks for your response. Your solution did not work for me. The Dropdown list shows 2 empty entries when the collection name is used:

    Empty dropdown.PNG

     

    When I use .Value property it gives me "All" but does not give me the employee names

    AllObjDropdown.PNG

    Here is the screenshot from File->Collection:

    Collection.PNG

     

    Many thanks for helping me on this.

     

    Additionally, how should I go about to append an item to a collection without "clearcollect" it and rebuild it?

     

    Thanks

  • Paul_C Profile Picture
    Microsoft Employee on at

    Oh, sorry about that! I see what the problem is. It's adding the list EmployeeName as one item. Apparently, ClearCollect() and Collect() are smart enough to infer that it needs to add an item for each item in EmployeeName as long as it is the only thing being added. As soon as you give it two things to add, it simply treats each as items without inferring anything.

     

    Anyway, the solution is a little odd looking, but very simple:

    ClearCollect(EmployeeList, "All"); Collect(Distinct(FeatureAccess, EmployeeName))

    Now "All" will be added and then the Collect will realize that we are giving it a list of items to add, and it will each one separately.

     

     

  • ManishM Profile Picture
    Microsoft Employee on at

    Apologies for the delay in responding. Your approach prepended "All" but also added blanks equal to Distinct list count. Below are  the screen shots. In the Collection screenshot, notice the 2 ways it is holding the info - Values and Results. "All" is in values and rest is in Results. I understand the difference but need to merge the 2. Thanks

    Dropdown.PNG

    Collection1.PNG

  • Verified answer
    ManishM Profile Picture
    Microsoft Employee on at

    Yes! I got !

     

    ClearCollect(BCategory, {Result:"All"});Collect(BCategory,Distinct('WPE Budget Category',BudgetCategory))

     

    The above line prepended "All" since I added/tricked the "All" entry to be part of "Result". Not a clean solution but does the job for me.

     

    Collection2.PNGDropdown2.PNG

  • SteveMC Profile Picture
    21 on at

    I think you can clean it up a bit like this:

     

    ClearCollect({Result:"All"}, Distinct('WPE Budget Category',BudgetCategory))

  • ManishM Profile Picture
    Microsoft Employee on at

    I never tried this way but curious what will be the name of the collection in this case?

  • SteveMC Profile Picture
    21 on at

    You're correct, the code is missing the collection name! Sorry about that...

     

    The first argument is the collection name, then you can have multiple items seperated by commas.

     

    ClearCollect( Collection, Item, ... )

    • Collection â€“ Required. The collection that you want to clear and then add data to.
    • Item(s) - Required. One or more records or tables to add to the data source.

     

    ClearCollect(BCategory, {Result: "All"}, Distinct('WPE Budget Category',BudgetCategory))

  • ManishM Profile Picture
    Microsoft Employee on at

    Just tried and it works! Thanks for refining the code.

  • TBStrauch Profile Picture
    2 on at

    Dear all,

     

    I know this discussion is a few years old already - but maybe anyway, somebody here can help me!?

     

    I am getting increasingly desperate as no matter what I do,

     

    ClearCollect(collectMembers; {Result:"All"});;
    Collect(collectMembers; Distinct(Vereinsmitglieder;VollstaendigeAdresse))

     

    as a data source for my Power App DropDown list (intended to be a filter drop-down) doesn't work. Note that "Vereinsmitglieder" is a SharePoint list containing a field called "VollstaendigeAdresse" with data like "Postal Code - [blank] - City Name" in it. However, of course, entries like "84189 Wurmsham" can appear 10 or 15 times in that list, so I try to distinct as I only want to see them once.

     

    Plus, as it is supposed to be a filter drop down, I would also want to have an "All" element in it - so that no filter would be applied.

     

    So I found the above code - but no matter what I do, I only get the "All" element in my drop-down. All the entries from the SharePoint List appear as blank elements, i. e., the drop-down has as many rows as I would retrieve from the (distinct) SharePoint list, but they don't show any text... And if I select them, my result Gallery will be filtered to empty...

     

    I truly hope someone can help me here - I am really running out of ideas...

     

    Thank you very much - looking forward to your replies... 🙂

     

     

    Cheers,

    Torsten

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard