I get the view limit exception when I make a request to the SharePoint online api that has more than 5K items in the view. I want to be able to count the number of items in the view without returning those items (thereby bypassing the exception).

Here is the ViewXml template that I use:

          <FieldRef Name="{2}"></FieldRef>
          <Value Type="DateTime">{0:yyyy-MM-dd}</Value>
          <FieldRef Name="{2}"></FieldRef>
          <Value Type="DateTime">{1:yyyy-MM-dd}</Value>

2 Answers 2


The answer is "no". There is no way to check for the number of items returned by a View. There is List.ItemCount but it will return the number of items in the list. Unfiltered.

If you need the number of items returned by the View you'll need to get the items and count them. Use "paging" to get around the 5K-Limit.

  • You can use RowLimit in the CAML, to stay below 5K
  • CamlQuery, as well as ListItemCollection has a ListItemCollectionPosition which is null when all items are read..

... so you'd need something along the lines of:

$list = Get-MyCoolList
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View><Query><Where>...</Where></Query><RowLimit>4999</RowLimit></View>";
do {
  $items = $list.GetItems($query);
  $query.ListItemCollectionPosition = $items.ListItemCollectionPosition;

  #  ... do cool stuff...

} while ($query.ListItemCollectionPosition -ne $null)
  • I use a Row Limit of 1,000 actually but I'm still getting the error.
    – user77232
    Commented May 21, 2019 at 21:20
  • So, how do you access SharePoint? REST?
    – Nils
    Commented May 22, 2019 at 5:07
  • I use the CSOM. I just can't seem to figure out why I'm getting the view limit.
    – user77232
    Commented May 22, 2019 at 14:23

When the list contains more than 5000 items, the columns you are querying must be indexed.


This solves my problem, but doesn't answer my original question. I would still like to know if there is a way to get the count without having to download all the rows.

  • Ah. I didn't see that coming. Views are simply a "filter". If your list contains more than 5000 items, you have to build a query/view that a) uses only indexed columns to do the filtering and b) returns less than 5000 items.
    – Nils
    Commented May 22, 2019 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.