How can I replace the space in between a file name in a calculated column in SharePoint list 2016?
Example I have a file name that contains ABC 123 and I want a calculated column to return the value ABC/123.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityHow can I replace the space in between a file name in a calculated column in SharePoint list 2016?
Example I have a file name that contains ABC 123 and I want a calculated column to return the value ABC/123.
If you are trying to use the SharePoint default file "Name" column (see below image) in calculated formula, then it is not possible.
It's a known limitation of SharePoint. We cannot use file name in calculated column formula.
There is a SharePoint UserVoice for this. You can vote here: Use filename in calculated field
Workaround:
Create a new text field & populate its value using workflow on item creation/update. Hide this field from property forms.
Use workflow to updated the Title field based on the filename. Then use Title field in the calculated column formula.
Using JSON formatting, we can do part of your requirements. I am not sure if there are a bunch of spaces inside the file name. If we are sure only one space needs to be replaced, we can use a simple JSON formatting on this. The replace function only works for the first instance of the specified value. Here is the white space.
A demo here:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"elmType": "span",
"txtContent": "=replace('[$FileLeafRef]',' ','/')"
}
]
}
And it will not work for the condition when we have multiple white spaces inside the file name. For that, I will suggest you to use a flow to directly get the file name, loop through the string and replaces all the white space with "/". And update the new new value to another single text column.