Is there any way of getting distinct values from a large(2000+ items) sharepoint list column?
I'm getting rather frustrated with always butting my head against sharepoint and Odata. I was just now attempting to use a timer to gather everything from a list in 2000 item batches and using distinct() in the app to process the data. Its a dirty hack, and I only mention it to illustrate how desperate I have become. And now I just realised that the problem with this latest desperate attempt, is that that the operators >, < doesn't work with the ID column! oh my, why!?😩
SharePoint has been a pain to deal with since day one when I started working on PowerApps solutions to replace Excel in various tasks. Now it looks like my endeavour is heading for a complete failure, as I always end up spending too much time on working around the limitations of sharepoint as a backend.
I think that Odata V4 will provide some more delegatable functions like groupby etc ($Apply) . anyone know if SharePoint will ever support Odata v4?
PS: I am not be able to make use of CDS or a SQL backend, the environment I work in will not allow for that. This has to be solved using sharepoint lists.
I think I got power automate "delegation" working. There was no obvious reason for it not working before, but I fixed it by putting each result into respective variables before applying a union() expression. this seems to be working well now and is able to retrieve distinct values from about 8000 items in just a few seconds.
In powerapps this flow-response object can be collected with:
ClearCollect(SomeCollection, 'PowerAutomateFlowName'.Run())
This requires the use of response which is a premium feature, so if this is to be considered a solution its only for those who have a premium.
The calculated column datatype, even when selecting its type as number, is not a number for powerapps, also the column cannot be indexed.hover tooltip error
Creating a numeric column with ID as calculated default gives me a error:
@Pstork1 's solution will work - just have a numeric field in SharePoint with the default of the ID.
If you are going to create a calculated column you can just do one that copies the ID. > or < don't work with the ID column itself, but it will work with an integer column, so you might try that.
I see @Pstork1 , however, this assumes that there are less than 2000 items that starts with each letter, in my case there are perhaps just 10 different letters at the start of the columns. Perhaps I could make a calculated column that generates a letter based on the ID value or something 🤔, but i guess since its not possible to use <> operators on ID in by powerapps, I guess calculation has the same limitation. And I guess its not possible to do filtering on calculated columns anyway.
In any case, its probably better than just starting from each end as I have currently done.
I have recently been exploring something I was able to do with large excel tables, but deploying the same method on SharePoint lists seems unstable for some reason. Sometimes it works and sometimes it just times out. The neat thing (if this worked) is that its fairly fast compared and less dependent on a good connection as the filtering and distinction logic is delegated to PowerAutomate / Flow
Each of the two get items get 4000 items from each direction with either one with orderBy ID asc or ID desc.
But sadly this does not seem stable as it times out at the response action. Everything is concerning sharepoint and union() finished in a few seconds similar to the screenshot posted, but then just idle at the response until it fails with a 504 Gateway Timeout. I have not figured out why yet.
The excel method I mentioned is described in this post. Its also note mentioning that I was able to get a large (6000+ items) collection into powerapps using this method, but it was obviously struggling when i tried loading the whole collection into a gallery or table 😄
Hi @hjaf ,
@Pstork1 has pretty much covered this.
I will as well endorse @mdevaney‘s method if it suits you as I have in the same frustration made a practice of having seperate lists for any common values under about 100 items. His idea on auto collecting is a good one - I had staff maintaining these.
In my case the distinct entries were based on names. So I did a collection where I pulled all the distinct Fullnames that started with "A", then "B", etc. Since I pulled all the A's and B's etc in one batch it was guaranteed that I only pulled the distinct since there would be no overlap between something that started with A and something that started with B. But it all depends on what you've to to work with as distinct fields.
@hjaf
My idea would be to store the unique values in a a new SharePoint list. I will provide some inspiration below. I’ve used a similar technique in SharePoint before but I had a different goal than you.
Example: Get A Unique List of Customers From A SharePoint List Of Customer Invoices
For example let’s say you have a SharePoint list for Customer Invoices. A customer may have one or more invoices. However, you want to obtain a list of unique Customers.
To do this we create a new SharePoint list called Customers.
Next we make a PowerApps form used to data enter new invoices into the Customer Invoices list. We put this code in the OnSuccess property of the form to check if the customer exists in the Customers list. If the customer does not already exist we PATCH them to the Customers list.
Set(myRecord, LookUp(Customers, CustomerName=Form1.LastSubmit.CustomerName));
If(IsBlank(myRecord),Patch(Customers, Defaults(Customers), {CustomerName=myRecord.CustomerName});
Now that we have a list of unique customers in SharePoint we can easily reference the unique names with this code.
Customers.CustomerName
Hopefully this brief example makes sense.
---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
WarrenBelz
637
Most Valuable Professional
stampcoin
570
Super User 2025 Season 2
Power Apps 1919
473