Skip to main content

Formula for Character-Count

  • November 12, 2016
  • 27 replies
  • 287 views

Forum|alt.badge.img+4

Has anyone worked out how to use the COUNT function to count the number of characters in a text string?

This topic has been closed for replies.

27 replies

Forum|alt.badge.img+4
  • Inspiring
  • November 12, 2016

I think LEN will do what you want.

COUNT counts the numeric items passed to it, e.g. COUNT(1, "hello", 5) returns 2.


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • November 13, 2016

Got it; many thanks!

A.


  • Participating Frequently
  • November 17, 2016

I think LEN will do what you want.

COUNT counts the numeric items passed to it, e.g. COUNT(1, "hello", 5) returns 2.


What is “LEN”?
Thank you


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • November 17, 2016

What is “LEN”?
Thank you


LEN(string): Returns the length of a string.


  • Participating Frequently
  • November 17, 2016

LEN(string): Returns the length of a string.


Thank you for the quick response. Useful, but it will not do what I would like to do - which is make a count of a list of states (2 letter codes) in another field.


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • November 18, 2016

Thank you for the quick response. Useful, but it will not do what I would like to do - which is make a count of a list of states (2 letter codes) in another field.


There are a few ways to tackle this, but they depend on where your two-letter state values are.

Are they comma-separated in one field? Or are they separate fields in one record? Or are you trying to count fields in multiple records?

In any case, Rollup might be ur solve:


  • Participating Frequently
  • November 18, 2016

There are a few ways to tackle this, but they depend on where your two-letter state values are.

Are they comma-separated in one field? Or are they separate fields in one record? Or are you trying to count fields in multiple records?

In any case, Rollup might be ur solve:


Thank you for persevering on this - it is good to check that I am not missing something which ought to be blindingly obvious! I do use roll-up for a different field and for that one it works a treat - but is not suitable for this one.

The data in the field in question is entered as space separated, 2-letter standard postal state codes in a single text field. In this particular case that is the easiest way to handle the information everywhere else I use it.

At least I learned what “LEN” stands for!


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • November 18, 2016

Thank you for persevering on this - it is good to check that I am not missing something which ought to be blindingly obvious! I do use roll-up for a different field and for that one it works a treat - but is not suitable for this one.

The data in the field in question is entered as space separated, 2-letter standard postal state codes in a single text field. In this particular case that is the easiest way to handle the information everywhere else I use it.

At least I learned what “LEN” stands for!


Hmm. Not sure yet how to crack it for ya.

If you had the states in separate fields, it’s easy to use COUNTALL and then also make a CONCATENATE field that creates what you have now; multiple states in one field.

https://airtable.com/shr9UovyUAH9r9p1U


  • Participating Frequently
  • November 19, 2016

Thank you for persevering on this - it is good to check that I am not missing something which ought to be blindingly obvious! I do use roll-up for a different field and for that one it works a treat - but is not suitable for this one.

The data in the field in question is entered as space separated, 2-letter standard postal state codes in a single text field. In this particular case that is the easiest way to handle the information everywhere else I use it.

At least I learned what “LEN” stands for!


Hi Kat

If, for example, the name of your field is “States” with string value similar to AA AB AC AD etc this formula should work for you:

IF(LEN(States) > 0, (LEN(TRIM(States)) - LEN(SUBSTITUTE(States, " “, “”))) + 1,”")

It handles empty cells, double spaces,and leading/trailing spaces

Have Fun,
Pete


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • November 21, 2016

Hi Kat

If, for example, the name of your field is “States” with string value similar to AA AB AC AD etc this formula should work for you:

IF(LEN(States) > 0, (LEN(TRIM(States)) - LEN(SUBSTITUTE(States, " “, “”))) + 1,”")

It handles empty cells, double spaces,and leading/trailing spaces

Have Fun,
Pete


Nice! How’s this working?


  • Participating Frequently
  • November 28, 2016

Hi Kat

If, for example, the name of your field is “States” with string value similar to AA AB AC AD etc this formula should work for you:

IF(LEN(States) > 0, (LEN(TRIM(States)) - LEN(SUBSTITUTE(States, " “, “”))) + 1,”")

It handles empty cells, double spaces,and leading/trailing spaces

Have Fun,
Pete


Thank you, Peter - that sounds like it will fill the bill perfectly! I will have to try that after clearing out my post-holiday work pile up!


  • Participating Frequently
  • December 2, 2016

Thank you, Peter - that sounds like it will fill the bill perfectly! I will have to try that after clearing out my post-holiday work pile up!


Works as desired! I give up being able to average the number of states since it is now text instead of a number, but that is an easy ‘price’ to pay. Thanks again, Peter!


  • Participating Frequently
  • December 10, 2016

Works as desired! I give up being able to average the number of states since it is now text instead of a number, but that is an easy ‘price’ to pay. Thanks again, Peter!


Oh, no trouble at all Kat, it was a fun challenge to work out :slightly_smiling_face:


Hi guys, Do you know how could I count words, instead of characters?


Hi guys, Do you know how could I count words, instead of characters?


@Diogo_Nogueira - I don’t know of a ‘simple’ solution, but here’s a workaround.

If NOTES is the name of the field you are trying to count words for, try:

LEN(Notes)-LEN(SUBSTITUTE(Notes," “,”"))+1

LEN(Notes) will count the total characters

SUBSTITUTE(Notes," “,”") will remove the spaces from Notes. Wrapping that in LEN will then count the characters in Notes without spaces.

Then we need to add one (1) to this, since the last word won’t have a space after it.

Be aware that if you use a space in the field you are counting, it will effectively tell this formula that there is a separate word.

Hope this helps! :slightly_smiling_face:


Forum|alt.badge.img+2
  • Participating Frequently
  • July 18, 2018

@Diogo_Nogueira - I don’t know of a ‘simple’ solution, but here’s a workaround.

If NOTES is the name of the field you are trying to count words for, try:

LEN(Notes)-LEN(SUBSTITUTE(Notes," “,”"))+1

LEN(Notes) will count the total characters

SUBSTITUTE(Notes," “,”") will remove the spaces from Notes. Wrapping that in LEN will then count the characters in Notes without spaces.

Then we need to add one (1) to this, since the last word won’t have a space after it.

Be aware that if you use a space in the field you are counting, it will effectively tell this formula that there is a separate word.

Hope this helps! :slightly_smiling_face:


Nice workaround Gareth,

To further prevent user error though, I would suggest to TRIM Notes to eliminate any leading and trailing spaces.

Kind regards,

Alex


@Diogo_Nogueira - I don’t know of a ‘simple’ solution, but here’s a workaround.

If NOTES is the name of the field you are trying to count words for, try:

LEN(Notes)-LEN(SUBSTITUTE(Notes," “,”"))+1

LEN(Notes) will count the total characters

SUBSTITUTE(Notes," “,”") will remove the spaces from Notes. Wrapping that in LEN will then count the characters in Notes without spaces.

Then we need to add one (1) to this, since the last word won’t have a space after it.

Be aware that if you use a space in the field you are counting, it will effectively tell this formula that there is a separate word.

Hope this helps! :slightly_smiling_face:


Thanks Gareth! I already found a solution! :grinning:


  • New Participant
  • February 20, 2019

Does anyone know how to make a word count formula?


Forum|alt.badge.img+17

  • New Participant
  • February 20, 2019

@Diogo_Nogueira could you share your solution?


Justin_Barrett
Forum|alt.badge.img+21

@Diogo_Nogueira could you share your solution?


Look at the reply by Gareth (above) for a solution.


  • New Participant
  • February 21, 2019

@Justin_Barrett When I tried that I got an error message.


Justin_Barrett
Forum|alt.badge.img+21

@Justin_Barrett When I tried that I got an error message.


@Kaiti_Hill Looks like the quotes in the version above got mangled somehow. Some are straight, others are curled. Try copying this, which is the fixed version that I tested successfully:

LEN(Name)-LEN(SUBSTITUTE(Name," ","")) + 1

  • New Participant
  • February 21, 2019

@Kaiti_Hill Looks like the quotes in the version above got mangled somehow. Some are straight, others are curled. Try copying this, which is the fixed version that I tested successfully:

LEN(Name)-LEN(SUBSTITUTE(Name," ","")) + 1

@Justin_Barrett you are WONDERFUL. thank you so much!!


Forum|alt.badge.img+1
  • Participating Frequently
  • August 9, 2019

So, I’m trying to come up with a way to complicate this and I believe I have found it. I have an ever changing array of characters that can be sequential but may not be (A, B, C, D, F… etc.) and I want to count the occurrence of each one in a much longer array (AAACCCBBDDIIFFIAAHDICCHAIKLA… etc.). I have my base structured such that one field (Field 1) keeps track of my changing array like above, and another field (Field 2) that keeps up with a concatenated larger array. Any one have any ideas on counting each character from Field 1 in Field 2?

Thanks!