Getting a total count of items in SPO list or library

Occasional Contributor

I know SPO has some kind of count of items in document libraries and lists, because I can see it on a ListEdit.aspx page, where it has a warning about going over the list view threshold. I just can't find out how to get it in one of my programs. Any programmatic interface would be fine (graph API, pnp, etc.), so long as it isn't fetching all the records and then counting them.

 

Hopefully this is an easy one, and I've just been searching with the wrong terms to find the right document. I don't need a working code sample, just the right function, other feature, or a link to a doc.

 

I'm looking for the grand total, but I'd also want to know if there's a way to get a count based on filtered items or search results where it's counting more than just the records that I could count myself in a JSON response. My intuition is that the latter would not be available, presumably because of how the load would not be great for MS's cloud. It seems pretty silly if I'd have to do something like a .../items/?$select=id&$top=5000 and just repeat via odata.nextlink until I reach the end.

2 Replies

@Jack_Eidsmsness for each view of your list or library you just need to edit the view, scroll down to Totals and select Count under whichever column you want the total.

 

countListSettings.png

 

CountList.png

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

@Jack_Eidsmsness , there is an ItemCount property on the list object that you can access via the various APIs (CSOM, REST).

But unfortunately this only gives you the grand total. If you want to know the number of items/documents in a filtered view, you will need to count them yourself.

Hth, Matthias