0

I have a simple custom list with multiple line column. I need to get count in each multi line column of the list item. (not word count)

As of now, I am exporting the list to excel and by using excel formula, getting the line count in each cell.

Is this possible in SharePoint list itself with a separate count column?

2 Answers 2

0

I don't think we can accomplish this with OOTB feature. By looking into excel formula, I was hoping to accomplish this with JSON column formatting. However, the issue is replace() function replaces only the first occurrence of '\n'. You can repeat replace() function though if you know the expected max line count, but will not be reliable.

You may try using MS Flow/Power Automate to accomplish this.

Excel Formula:

=LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1

JSON Column Formatting:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=indexOf([$Multiline] + '^', '^') - indexOf(replace([$Multiline], '\n', '') + '^', '^') + 1"

}

However, you can repeat replace() function to a known max number like below to accomplish your goal. But the result count might not be accurate if the actual line number is > then the number of times replace() used in the JSON.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=indexOf([$Multiline] + '^', '^') - indexOf(replace(replace(replace(replace(replace(replace([$Multiline], '\n', ''), '\n', ''), '\n', ''), '\n', ''), '\n',''), '\n','') + '^', '^') + 1"
}

0

I know this post is a bit old, but wanted to share this with any others that come across the post. I discovered an answer while browsing Microsoft's documentation here: https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/formatting-syntax-reference

I used a combination of split() and length() (only works with arrays). This way you don't need to nest a bunch of replace() functions. Use split() to divide the multiline field into an array of strings, separated by the specified character, in this case \n (i.e. new line). Then use length() to count the number of items in the array created by split().

"txtContent": "=length(split([$Multiline], '\n'))"

Disclaimer: I used this with a plain text multiline field, and have not tested with rich text or enhanced text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.