How do you create a calculated column using PowerShell? In my example, I’m creating a new field called Calculated Date Field, setting the formula, then setting the output type to DateTime.
How do I build the formula? Go into your list, add a new calculated column, create your formula, test the formula. If it works, copy the formula and delete the column.
$site = Get-SPweb "http://sharepointed.com/site/salsa/"
$mList=$site.Lists["Nacho"]
$mList.Fields.Add("Calculated Date Field", "Calculated", 0)
$SPField = $mList.Fields.GetField("Calculated Date Field")
$SPField.Formula="=DATE(YEAR([Document Date])+7,MONTH([Document Date])+0,DAY([Document Date])+0)"
$SPField.OutputType="DateTime"
$SPField.Update()
$site.Dispose()
Nice Post. Helped me a lot. Thanks!
i cant add the calculated column its saying “Property ‘Formula’ cannot be found on this object; make sure it exists and is settable”
@ Poonam
Did you replace “Document Date” with your own field? Try using one of the SharePoint default date fields (created or modified).
Pingback: SharePoint list views filtered by date AND time « Thornton Technical