Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Count the number of words in a column

sreekanthac
8 - Asteroid

 

Hello Community,

 

I have a situation where I need to count the number of words in a column. The words are separated by comma. I know using CountWords() we count the words in a string where they are separated by space. How can I do the same when they are separated by comma? Thank you in advance for your support. 😊

 

sreekanthac_0-1637733946446.png

 

5 REPLIES 5
Sebastiaandb
12 - Quasar

@sreekanthac 

 

Here you go!

 

Sebastiaandb_0-1637735181944.png

 

Use this expression: CountWords(REGEX_Replace([Field2], ",", " ")) 

were field 2 is your concat_type field. The regex replaces the commas by a space, making it possible for the countwords to do its magic!

 

Greetings,

 

Seb

 

sreekanthac
8 - Asteroid

Thanks Seb for the quick response. I tried with a similar solution like yours as shown below and it worked. But I was looking for function like CountWords() where I could provide the delimiter as an option. 

 

My logic is as shown below and it worked. I was wondering why you used REGEX_Replace() instead regular Replace(). Do you have an explanation for that?

 

CountWords(Replace([Concat_Type], ',', ' '))

Sebastiaandb
12 - Quasar

Hi @sreekanthac 

 

Your replace expression does exactly the same as the stacked countwords/regex expression. The deliminator "comma" is provided in the REGEX_replace function as well between the quotations. 

 

It doesn't matter in this case whether to use the replace or regex_replace function. You would want use the REGEX_replace function when you want to replace the comma on specific positions within a sentence only but keep some other commas (you could say, a harder replace).  

 

Greetings,

 

Seb

 

Joma
7 - Meteor

Hi there,

 

I have a question. In this specific scenario from sreekanthac. How would it be possible to count each word which occurs in the column Concat_Type?

So that I would have a list like this

 

Joma_0-1654077337425.png

Thanks in Advance

sbatra116
8 - Asteroid

@Joma

 

select the output and use formula CountWords([Text])

Labels