6 Replies Latest reply on Mar 10, 2014 10:08 AM by Douglas Manning

# Count characters/letters in a string

I am trying to figure out how to count the number of times the letter "o" shows up in a string. The calculation will be used to find and count other combinations of letters, but for simplicity I think the example below will demonstrate what I am looking to do.

Thank you!

-Douglas

 String Count John Doe 2
• ###### 1. Re: Count characters/letters in a string

I tried everything I could to make this work, but couldn't ever get a solution within Tableau.  That doesn't mean it isn't possible, but I sure couldn't find a way.

• ###### 2. Re: Count characters/letters in a string

You can achieve this by finding the length of the string then subtracting the length of a string where you've replaced the the characters you're trying to find with nothing and divided by the length of the characters you're trying to find:

(len([Fullname])-len(REPLACE([Fullname],[findstr],"")))

/ len([findstr])

1 of 1 people found this helpful
• ###### 3. Re: Count characters/letters in a string

Tom: I am unable to follow your logic--can you provide an example?  Simply copy and paste "John Doe" as a record into Tableau, and apply your solution so we can see it working.  I'm not able to follow what you are suggesting here.

• ###### 4. Re: Re: Count characters/letters in a string

My formula above was the example. Substitute Fullname with the field you're searching, and findstring with the string you want to find.

I've attached a workbook example.

• ###### 5. Re: Count characters/letters in a string

Thanks for clarifying--this is great!  It would be wise to use the UPPER or LOWER value of the string you are searching for, so case sensitivity is not an issue.

• ###### 6. Re: Count characters/letters in a string

Tom: Awesome work... I knew there was a way!

Matthew: Thanks for the tip!