One of my column in an attribute table in QGIS is separated by comma (shown by column "N") and I wanted to count elements in it. The column is a text field string.

enter image description here

  • 1
    Welcome to GIS SE! It is recommended to take the tour, and familiarise yourself with how to ask a good question before posting. In particular, provide evidence that you have researched the problem, examples of what you have already tried, and be specific about what went wrong.
    – Matt
    Oct 25, 2021 at 11:27
  • 3
    You only need to count the numbers of , per field and add 1.
    – Erik
    Oct 25, 2021 at 11:33
  • 1
    @Erik that would return 1 if the field is empty
    – JGH
    Oct 25, 2021 at 13:09
  • Yeah, but I can only work with what OP provides and not make contigencies for every possible exception ;-) @JGH
    – Erik
    Oct 25, 2021 at 13:46

1 Answer 1


Use this expression with field calculator: array_length (string_to_array (N))

enter image description here

  • I recommend using double quotes "" for field names, e.g. "N"
    – Taras
    Oct 25, 2021 at 13:27

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.