SharePointVault ~/gotchas/search ⌕ Search 404 pages, error messages, scripts…Ctrl K ★ Star
M↓ README.mdM↓ viewsx-properties-sort-only-by-viewslifetime.md
sharepoint-vault›gotchas›search›viewsx-properties-sort-only-by-viewslifetime.mdhistoryedit on GitHub
● GOTCHAsearch· 1 min read

ViewsX managed properties: sortable only by ViewsLifeTime

applies to: SharePoint Onlinereviewed: 2026-07-16#search#analytics#managed-properties

Of the ViewsX analytics properties only ViewsLifeTime sorts reliably, so sort by it and do the time-windowing client-side — the windowed variants like ViewsLast7Days select fine but break in sortlist.

Z analytických vlastností ViewsX řadí spolehlivě jen ViewsLifeTime, takže řaď podle ní a časové okno dopočítej na klientu – okenní varianty jako ViewsLast7Days se dají vybrat, ale v sortlist selhávají.

Symptom

Building a "most read this week" widget on SP Search, you sort by the obvious property:

sortlist='ViewsLast7Days:descending'

The query returns nothing (or garbage order). Sorting by ViewsLastMonths1 — same. Yet both properties select just fine, so the data clearly exists.

Cause

Of the analytics-backed managed properties, only ViewsLifeTime behaves as a reliable sort key. The windowed variants (ViewsLast7Days, ViewsLastMonths1, …) work as selectproperties but not dependably in sortlist — and to add insult, ViewsLast7Days often reports 0 across the board anyway.

Fix

One query, sorted by the property that works; do the windowing client-side:

querytext='…'&sortlist='ViewsLifeTime:descending'
&selectproperties='Title,Path,ViewsLifeTime,ViewsLast7Days,ViewsLastMonths1'

Take a generous rowlimit, then re-rank/filter in code with whatever window values came back — with a fallback to lifetime views when the windowed numbers are zeros.

Notes

  • Tempted by Graph instead? GET /sites/{id}/analytics returns HTTP 200 with allTime: null on many tenants — check for the 200-with-null case before trusting it, and fall back to getActivitiesByInterval(...interval='day') (max ~90 days) when you need real numbers.
  • Search analytics lag by design (hours to days) — don't promise real-time popularity, whatever property you sort by.
Was this helpful?ask or add your experience on GitHub →
Saved you an hour? A star on GitHub helps other SharePoint people find the vault.★ Star on GitHub
last reviewed: 2026-07-16last updated: 2026-09-24historyedit on GitHubview source