6 Replies Latest reply on Jul 19, 2017 4:56 PM by Tom W

# Understanding split formula

I don't quite understand the split formula. This is the exmaple they give.

Split('a-b-c-d', '-', -2) = 'c'

What is it doing?

• ###### 1. Re: Understanding split formula

'a-b-c-d' is your string, '-' is the separator used and '-2' position (from end of string 2 positions) thus = c

• ###### 2. Re: Understanding split formula

To add to Mihai's response, you can use 2 to get the 2nd token from the left and -2 to get the 2nd token from the right.

• ###### 3. Re: Understanding split formula

Right above that example you've quoted from the help is a very thorough explanation.

Returns a substring from a string, using a delimiter character to divide the string into a sequence of tokens.

The string is interpreted as an alternating sequence of delimiters and tokens. So for the string `abc-defgh-i-jkl`, where the delimiter character is ‘-‘, the tokens are abc, defgh, i, and jlk. Think of these as tokens 1 through 4. SPLIT returns the token corresponding to the token number. When the token number is positive, tokens are counted starting from the left end of the string; when the token number is negative, tokens are counted starting from the right.

1 of 1 people found this helpful
• ###### 4. Re: Understanding split formula

Hi Mihai. From end of string 2 positions is c.... "d" "-" and then "c".....but what does the "-" have to do with anything?

• ###### 5. Re: Understanding split formula

Thanks Tom. That makes sense.

• ###### 6. Re: Understanding split formula

I'd also like to provide some general advice here - throw the formula into Tableau and change the parameters around to see how it affects the output.

Don't forget, you don't even have to create calculated fields. You can very quickly just throw these calcs on the row or column shelf and start playing around;

Adjust the parameters, see what happens. It's the best way to learn

1 of 1 people found this helpful