Skip to main content
Community site session details

Community site session details

Session Id : 84ja6BDeUds8A4bii0udg9
Power Apps - Building Power Apps
Answered

Delegation workaround for Distinct()?

Like (0) ShareShare
ReportReport
Posted on 9 Nov 2021 17:50:57 by 664

I have a canvas app where data source is Dataverse. Screen in app shows gallery connected to a list containing Products. Each product has a category field and an item description field. On this screen, I want the gallery to show a distinct list of categories and then we'll click into the category to see its items.

 

The actual categories displayed have some additional conditional logic based on the products themselves (such as quantity in stock), therefore I cannot point this gallery directly to the choices source for the product category.

 

I know Delegate is one of the functions that won't throw a warning but is not delegable, so 

 

Distinct(Purchases, Category)

 

won't scale. Does anyone have any other ways to get a distinct value set? Not seeing any options within the Dataverse view and with scalability being the main goal I would like to avoid caching data onstart.

  • thinh_noz1 Profile Picture
    13 on 21 May 2024 at 11:02:13
    Re: Delegation workaround for Distinct()?

    I can confirm that this will not work at all. Gallery only load 500 items each batch and only load more items when you scroll all the way down to bottom of the gallery. So putting Distinct in second gallery only gives you the Distinct records of first 500 items from data source in the first gallery. Rather just put the delegation limit to the max 2000 and using straight Distinct(Your_Data_Source) so you can get Distinct values of 2000 records (in case you expect the number of items will not go over 2000) or using Power Automate than using this 2 galleries solution

  • jfsimpson3 Profile Picture
    2 on 05 Jan 2023 at 15:26:34
    Re: Delegation workaround for Distinct()?

    An alternative solution to using powerautomate or throwing the data into a collection during AppStart or on the page's OnVisible property is to leverage a second hidden gallery. 

     

    First create two galleries. 

     

    In the Items property of the first gallery (the one that is to be hidden aka visible=false), add your data source as well as any filters you'd like to apply. 

     

    In the second gallery (which is visible), set the items property to =Distinct('Gallery1Name'.AllItems,'DistinctColumnName').

  • Cooper01 Profile Picture
    664 on 09 Nov 2021 at 19:13:54
    Re: Delegation workaround for Distinct()?

    Thank you for the response @Pstork1 . Not sure yet if this is the solution I will go with but glad to know I am not missing anything simpler.

  • Verified answer
    Pstork1 Profile Picture
    67,342 Most Valuable Professional on 09 Nov 2021 at 17:56:21
    Re: Delegation workaround for Distinct()?

    The only option I can suggest is to use a Power Automate recurrence flow to sync a copy of the distinct values to another table in Dataverse.  Then use that table for your gallery.  Power Automate doesn't have the same limitations on delegation that Power Apps does.  The only other way to do this is to use a delegable function to sync a copy of the full table to a local collection and then do Distinct on that.  But the performance on that will be poor.

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

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete