No I'm pretty sure you can't count occurrences of words. The closest you can get is to see if a word exists using the CONTAINS function. You can parameter this so the user can type in a word, and just the rows containing that word will remain (or you can do a count on the number rows containing that word, but if it occurs in the same string/row twice it would only evaluate to true, so no count).
As a starter for 10 (as I don't know your final use case)
Create a Parameter, as a String with All selected.
Then create a calculated field
IIF (CONTAINS([your string], [parameter.created]),"Show', "Hide")
Show the parameter control, put the new field in the filter and select 'Show', and type something into the parameter. This will only leave Rows/Strings that meet the criteria in the view. Equally you could wrap it in a COUNT and get a count.
Hope this helps
No-need to reshape data. This is do-able in v8 and earlier, see #18-20 in String Calculations in Tableau - Clearly and Simply (a great resource by Robert Mundigl). It's possible to build something for that though you have to account for the following:
- word at beginning of line
- word at end of line
- repeats of word
In v9 and beyond, if you have the REGEX functions should work (in a supported data source). I don't have time to get to this today, if you need some help let me know!
PS: I found Robert's solution by doing a Google search for "Tableau count number of words in string", it was #3 in the search results where #1 was this particular thread.
Thank you very much.
I will definitely let you know after I am sure about the view I want to
3 of 3 people found this helpful
PPS: If you aren't looking to count words (i.e. bits of text surrounded by spaces) and just want to count occurrences of a substring inside a string, then it gets simpler because you can just do (LEN([Text])-REPLACE([Text],[Param],""))/LEN([Param]).
Hi - very helpful link/code. I did have to make a slight modification. (LEN([Text])-LEN(REPLACE([Text],[Param],"")))/LEN([Param]). Thanks!!