If you try to create a calculated column with a formula containing [Today] or [Me] SharePoint gives the error :
“Calculated columns cannot contain volatile functions like Today and Me”
There are a few reasons you might want to do this. One would be to display how many days left you have to complete something, the other is to only show things added in the last X days or due in the next X days.
There are many pages mentioning this workaround :-
1) Create a dummy column called “Today”, then add your calculated column using [Today] in the formula, finally delete the dummy column. If you need to edit the formula then you have to go back to the start and add the dummy column again.
2) Optionally you can create a calculated column called “My Today” and set its formula to =[Today] using the trick above. Reference [My Today] in your other calculated columns. Thus you reference [My Today] which in turn references [Today]. Then you will not have to add the dummy column back in every time you want to edit formulae.
You then pat your self on the back and head home after another successful day of harassing SharePoint to do what you want, Hurrah!
But the next day you take a look at your list and its wrong. The formula has not updated and its still showing yesterdays value. DOH! SharePoint has made a fool of you after all.
Turns around there is actually a good reason for SharePoint not allowing volatile functions like [Today] or [Me] in calculated columns.
“Calculated fields don’t update themselves until item itself is updated.”
Read that again.
The value of a calculated column is only updated when item is edited and in the mean time you will see incorrect calculations every time you look. In fact, for most uses, this trick don’t give you anything more than just referencing the [Modifed] column.
One workaround to the workaround problem is to write a console app to find all these lists that use the [Today] trick and update them automatically once per day. But this workaround to the workaround problem may not be without its own problems that need to be worked around….
Depending on your need there may be a simpler way – turn the problem on its head!
In the example of using a calculated column to filter out items due in x days or overdue SharePoint will accept [Today] as part of the Filter but will not as part of a calculated column – so give it what it wants
[EDIT- WSS 3 / MOSS 2007 now accepts this]
- Use a filter of [Created] is greater than [Today]-7
(Note – its essential to have no spaces; [Today] – 7 will not work but [Today]-7 does.
WSS 2 / SPS 2003
- Create a column called “Filter 7 Days” and formula as =Created+7
- Then use a filter of “Filter 7 Days” is less than [Today]
See this page for more details – http://blog.pentalogic.net/2008/10/advanced-sharepoint-view-and-filters/
So the calculated column is not dynamic (it will never need updating unless the record itself changes) and SharePoint is happy – but the filter is dynamic and you are happy!
If you want a countdown in your view (i.e. Days left to complete a task) then take a look at this post – http://pathtosharepoint.wordpress.com/2008/08/25/a-countdown-for-tasks-lists/
– check out our Highlighter product if you want count-down to Today (e.g. 5 days left, 10 days overdue)
– or check out Reminder if you want “Alert Me” type emails when a task is due soon or overdue.
[EDIT] As it’s been pointed out to me the tone of this article was off from what I intended – the intention is to make clear that this well known and oft mentioned trick does not work as you might expect and to offer alternatives.
|Free SharePoint Calculated Column Cheat Sheet
|a handy 3 page reference for calculated column functions and formulas.