You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Add-PnPField - [Regression] throws "Syntax error" when adding Calculated Column with Document ID dependency #5188
Reporting a regression where Add-PnPField fails to add an existing Calculated Site Column to a list (specifically a calculated column dependent on the 'Document ID' field). While this operation completes successfully via the SharePoint UI, the PnP command now fails.
This script logic, which we use for provisioning each newly created site, functioned correctly for over a year and started failing approximately 2 months ago.
### Expected behavior
When executing Add-PnPField -List -Field , I expect the cmdlet to successfully add the existing site column to the library, automatically resolving the dependency on the Document ID field, just as the SharePoint UI does.
### Actual behavior
The command fails with an error when attempting to add the column.
Error message: "An error occurred while adding the site column 'COLUMNNAME ' to library 'LIBRARY NAME': The formula contains a syntax error or is not supported."
Observation: The issue seems specific to Calculated Columns referencing the Document ID. The cmdlet appears unable to validate the formula context during the add operation (likely due to the Document ID dependency not being resolved yet), whereas the UI handles this correctly.
### Steps to reproduce behavior
Activate Document-id-service on site level (_layouts/15/ManageFeatures.aspx?Scope=Site)
At the site collection level: Create a Calculated Site Column (e.g. named "TESTBUG") which includes the Value Document ID
Run a PnP PowerShell script to add this existing column to the library. The last line will cause the error.
Notice manually adding the column to a library via the UI works fine.
###Workarounds Attempted
To isolate the issue, we attempted several alternative implementation methods, but all resulted in the same failure:
XML Provisioning (Add-PnPFieldFromXml): We attempted to add the field using its full XML schema definition.
Content Type Approach (Add-PnPFieldToContentType): We attempted to add the field directly to the list's Content Type instead of the list itself.
Object-based Approach: We first retrieved the site column object using Get-PnPField and passed the object to the -Field parameter (instead of the string name) to ensure the correct ID/Context was used.
None of these methods succeeded. This strongly suggests the issue lies in the underlying validation logic for Calculated Columns referencing Document ID during the provisioning phase.
What is the version of the Cmdlet module you are running?
@Kiphouder - did you try with a different column which is not dependent on the Document ID ?
Dear @gautamdsheth , I didn't. Focus was on solving the problem and trying different calls to add the column we really need which includes Document ID.
I assume the community would have reported the regression when it isn't this specific use case.
@Kiphouder : Would you be able to share the formula used in that calculated column so we can try to reproduce the issue? It may also be worth testing with the latest 3.1.0 module or the current nightly build to see if the behaviour persists.
@Kiphouder : Would you be able to share the formula used in that calculated column so we can try to reproduce the issue? It may also be worth testing with the latest 3.1.0 module or the current nightly build to see if the behaviour persists.
Dear Reshmee,
Thank you for looking into this.
The error is caused by any formula that references the Document ID column.
Please find the reproduction steps in the original post. Even a minimal formula like =[Waarde van de document-id]* causes the Add-PnPField command to fail.
/* My UI is Dutch. Probably in English UI you can add the column by doubleclick something like "Value of the document-id" when adding the Calculated Site Column in step 2 of my original post.
Calculated Column (Simple): Formula ="1" (No reference to other columns) -> Success.
Calculated Column (Referencing): Formula referencing to another column (Doc ID, but also Title, Created) -> FAIL.
Result: Add-PnPField fails whenever a Calculated Column references any other field.
Testing with Raw CSOM (XML Injection)
To see if I could bypass the issue, I also tried the raw CSOM approach (which I haven't used before for this process):
Result: Interestingly, this approach also fails with the same error when the formula references another field. However, adding the exact same Site Column via the SharePoint UI works perfectly. This discrepancy between the UI and the code-based methods (both PnP and CSOM) is what I am trying to understand.
Side Finding: Regression/Issue with View Cmdlets
We cannot use -AddToDefaultView in the same command when adding an existing site column (Add-PnPField). This is expected behavior, that is why we always first added the Column to the library and then added it to the default view with below code:
Since the problems, this part also fails. Even if the column is already added to the library via the UI, Add-PnPViewField (and its successor Add-PnPViewColumn) fails. This worked until the problems with Add-PnPField appeared.
Curiously, direct manipulation of the view via CSOM does work. Even when targeting a Calculated Column with reference to another column.
Result: Direct CSOM works for views, but the PnP cmdlets do not anymore.
My thoughts:
A. Add-PnPField Regression: Maybe the PnP command broke because of a problem/change in the API.
B. Add-PnPViewField Regression: There appears to be a specific regression here as well. The cmdlets fails, but CSOM ViewFields.Add() method works, so the SharePoint functionality is intact. This points towards an issue within the cmdlet logic itself.
I hope this detailed analysis helps you narrow down where these regressions were introduced.
I could add a site calculated field referring to Title and Created to a list.
However it is failing for [Document ID Value] with message
"Add-PnPField: The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column."
Add-PnPField -List $listName -Field $columnName
Did the cmdlet ever worked in the past? The Document ID field is a complex hidden field which may explain why it is failing. The underlying code is using CSOM in the background. I tried with the REST API endpoint and got same error message:
"Error adding field: {"odata.error":{"code":"-2130575273, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column."}}}"
Activity
gautamdsheth commentedon Dec 16, 2025
@Kiphouder - did you try with a different column which is not dependent on the Document ID ?
Kiphouder commentedon Dec 16, 2025
Dear @gautamdsheth , I didn't. Focus was on solving the problem and trying different calls to add the column we really need which includes Document ID.
I assume the community would have reported the regression when it isn't this specific use case.
reshmee011 commentedon Dec 20, 2025
@Kiphouder : Would you be able to share the formula used in that calculated column so we can try to reproduce the issue? It may also be worth testing with the latest 3.1.0 module or the current nightly build to see if the behaviour persists.
Kiphouder commentedon Dec 27, 2025
Dear Reshmee,
Thank you for looking into this.
The error is caused by any formula that references the Document ID column.
Please find the reproduction steps in the original post. Even a minimal formula like =[Waarde van de document-id]* causes the Add-PnPField command to fail.
/* My UI is Dutch. Probably in English UI you can add the column by doubleclick something like "Value of the document-id" when adding the Calculated Site Column in step 2 of my original post.
gautamdsheth commentedon Dec 28, 2025
@Kiphouder - can you please try with another column , not depending on document ID and let us know ? This would help us narrow it down.
Kiphouder commentedon Dec 29, 2025
@gautamdsheth I have performed extensive testing again to isolate the issue. Here are my findings:
Result: Add-PnPField fails whenever a Calculated Column references any other field.
To see if I could bypass the issue, I also tried the raw CSOM approach (which I haven't used before for this process):
Result: Interestingly, this approach also fails with the same error when the formula references another field. However, adding the exact same Site Column via the SharePoint UI works perfectly. This discrepancy between the UI and the code-based methods (both PnP and CSOM) is what I am trying to understand.
We cannot use -AddToDefaultView in the same command when adding an existing site column (Add-PnPField). This is expected behavior, that is why we always first added the Column to the library and then added it to the default view with below code:
Since the problems, this part also fails. Even if the column is already added to the library via the UI, Add-PnPViewField (and its successor Add-PnPViewColumn) fails. This worked until the problems with Add-PnPField appeared.
Curiously, direct manipulation of the view via CSOM does work. Even when targeting a Calculated Column with reference to another column.
Result: Direct CSOM works for views, but the PnP cmdlets do not anymore.
My thoughts:
A. Add-PnPField Regression: Maybe the PnP command broke because of a problem/change in the API.
B. Add-PnPViewField Regression: There appears to be a specific regression here as well. The cmdlets fails, but CSOM ViewFields.Add() method works, so the SharePoint functionality is intact. This points towards an issue within the cmdlet logic itself.
I hope this detailed analysis helps you narrow down where these regressions were introduced.
reshmee011 commentedon Dec 31, 2025
I could add a site calculated field referring to Title and Created to a list.
However it is failing for [Document ID Value] with message
"Add-PnPField: The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column."
Did the cmdlet ever worked in the past? The Document ID field is a complex hidden field which may explain why it is failing. The underlying code is using CSOM in the background. I tried with the REST API endpoint and got same error message:
"Error adding field: {"odata.error":{"code":"-2130575273, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column."}}}"
I would advise to raise the bug with Microsoft to see if they can help fix the underlying API.
reshmee011 commentedon Jan 14, 2026
I am moving it to discussion as it's something in the Microsoft backend preventing this particular scenario.