I have two almost identical calculated fields that I want to add to a list on several sites through Powershell .

"Calculated risk" formula:


"Revised calculated risk" formula:

=[Revideret konsekvens]*[Revideret sandsynlighed]

Trying to add the first column "Calculated risk" will work. However, "Revised calculated risk" with the above mentioned formula will fail on the current line of code:

$riskList.Fields.Add($site.RootWeb.Fields["Beregnet revideret risiko"])

It throws this error:

The formula refers to a column that does not exist...

I am using the following PowerShell code-snippet for both columns:

$calcRiskField = $riskList.Fields["Beregnet risiko"]
if($calcRiskField -eq $null) {
    $riskList.Fields.Add($site.RootWeb.Fields["Beregnet risiko"])
    Write-Host Added Beregnet risiko field -ForegroundColor Yellow

$calcRevisedRiskField = $riskList.Fields["Beregnet revideret risiko"]
if($calcRevisedRiskField -eq $null) {
    $riskList.Fields.Add($site.RootWeb.Fields["Beregnet revideret risiko"])
    Write-Host Added Beregnet revideret risiko field -ForegroundColor Yellow

I have checked to see if the columns exist on the list and they do. I have checked to see if SharePoint UI throws any errors in the formular and it does not. I have tried to add the column through SharePoint UI and that works fine.

The error seems to be connected to the formula where the two columns have spaces in the display name, since it works for calculated columns where the display names are one word.

Any ideas?

  • Can you post your PS code Commented Nov 30, 2015 at 18:17
  • @DannyEngelman Added PS code. Commented Dec 2, 2015 at 14:31
  • Try doing it without any spaces in the Column names Commented Dec 2, 2015 at 14:39
  • @DannyEngelman as I mentioned the first calculated column works with fields without any spaces in their display names and the second one with fails - so that will probably fix it. However, in my opinion spaces in the display name should not be an obstacle, as it works fine through SharePoint UI. I guess that I can make an empty calculated column, add it through PS and then change the formular afterwards and depend on SharePoint to update all list using the column as a quick fix. Commented Dec 3, 2015 at 7:38

1 Answer 1


SharePoint (UI) converts Column Names with spaces to URL encoded notation.

Check the URLs in the List settings, at the end Internal Fieldname is shown: &Field=xxxxx

So when using code you have to use the same notation if you want spaces in the name.

  • If you mean try to add the field by retrieving it by its internalName I have tried that with the same result. Example: $riskList.Fields.Add($site.RootWeb.Fields.GetFieldByInternalName("Beregnet_x0020_revideret_x0020_risiko")) Commented Dec 8, 2015 at 14:15
  • Could it be an issue between Powershell (string notation?) and SharePoint, I have never experienced any issues with spaces when using JSOM code to create Fields with Formulas. Commented Dec 8, 2015 at 14:28
  • I think it is an issue in SharePoint, even though I am not sure what exactly. I have now tried the quick fix I mentioned earlier and to my surprise I recreated the error from PowerShell through the SharePoint UI. I changed the formular to "=2*2" and added the field through PowerShell. Then I edited the field on the rootweb and changed the formular to the intended value (=[Revideret konsekvens]*[Revideret sandsynlighed]). It then fails the first time with a correlationid and the same error in ULS, but if I go back and press OK once more it works. Commented Dec 8, 2015 at 14:50

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.