Showing Recent Items in a SharePoint View
Update 16 October 2000: Thanks for all the comments below. Based on these, here are some corrections:
1. You can use “[Today]-5” directly in the view so avoiding adding new fields etc. to the list or library.Why didn’t I? Well, if you add spaces around the “+” so the expression reads “[Today] – 5” you will receive an error back from SharePoint: “Filter value is not in a supported date format”. I normally add spaces as I think it makes it more readable. Remove the spaces, and the view will update. The result should look like:
(Thanks to Joe at Cork County Council for helping discover the issue with spaces)
2. When doing date calculations you can simply add or remove a number of days rather than the long-winded formula used below.
When lists have many items it’s useful to be able to display only those items created or perhaps modified in the last number of days. Since expressions cannot be added to filters in views a calculated column needs to be added to track the age of the item.
You might be tempted to use [Today] in the site column expression to calculate the number of days since the item was created. You will be able to save the site column, but when you add the column to the list the following error is displayed:
“Calculated columns cannot contain volatile functions like Today and Me.”
This is because the values are calculated when the items is saved, and not when the item is queried.
The way around this is to create a calculated site column, called for example “DaysOld”, with the following expression:
Where “5” is the number of days to be used in the filter (e.g. “show items created in the last five days”). This expression will calculate the date five days on from when the item was created. It should look like:
You should now add this site column to the list which needs to be filtered. A view on that list can now have a filter expression that uses this calculated field:
“[Today]” can be used in the filter expression since its value is known when the query is executed, and so is determinate.