cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Is there absolutely no way of getting distinct values from a large sharepoint list?

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. 

12 REPLIES 12
Highlighted
Dual Super User III
Dual Super User III

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

About the only way to do it is similar to the way you are doing it now by pulling everything into a local collection.  The way I've been doing that without the ID column or a timer is to build the collection using 26 Filter() statements to filter the content using StartsWith() on a text column.  You could easily add a Distinct() to this and filter it further to end up with a Distinct set of fields in a collection.  But without moving to SQL I don't know another way to do it.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Helper V
Helper V

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

Ok, but how do you make sure that you don't pull anything twice? and how can you make sure no items will be missed?

The closest workaround I just came up with is querying twice with SortByColumns() (ascending and descending) on the ID and then just join those two with coalesce, this is also gathering the same information twice in the intersection. This may extend the ability provide distinct values to 4000 items. This the equivalent of wetting my pants to keep warm, as we will probably reach the 4000 items very soon.

I'm using two columns to find a distinction in this example. 

ClearCollect(
    TestCollection,
    Distinct(
        Coalesce(
            Distinct(
                SortByColumns(OFP_MASTER, "ID", Descending),
                SCOPE.Value & " - " & YEAR
            ),
            Distinct(
                SortByColumns(OFP_MASTER, "ID", Ascending),
                SCOPE.Value & " - " & YEAR
            )
        ),
        Result
    )
)

 

I guess I will have to create a flow that maintains yet another list for this very purpose, maintenance is starting to pile up 😄

 

 

Highlighted
Super User III
Super User III

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

@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."

 

 

Highlighted
Dual Super User III
Dual Super User III

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Super User III
Super User III

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

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.

Highlighted
Super User III
Super User III

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

@WarrenBelz
I’m glad to hear you do this too. I figured this out for myself awhile ago but I was starting to wondering if many others were doing it.
Highlighted
Helper V
Helper V

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

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 

image.png

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 😄

 

 

 

Highlighted
Dual Super User III
Dual Super User III

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

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.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Super User III
Super User III

Re: Is there absolutely no way of getting distinct values from a large sharepoint list?

@Pstork1 's solution will work - just have a numeric field in SharePoint with the default of the ID.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (5,973)