Early Access: The content on this website is provided for informational purposes only in connection with pre-General Availability Qlik Products.
All content is subject to change and is provided without warranty.
Skip to main content Skip to complementary content

Index - script and chart function

Index() searches a string to find the starting position of the nth occurrence of a provided substring. An optional third argument provides the value of n, which is 1 if omitted. A negative value searches from the end of the string. The positions in the string are numbered left to right from 1 and up.

Syntax:  

Index(text, substring[, count])

Return data type: integer

Arguments
Argument Description
text The original string.
substring

A string of characters to search for in text.

Information noteIf the substring does not exist in the text, Index returns 0.
count Defines which occurrence of substring to search for. For example, a value of 2 searches for the second occurrence. A negative value starts from the end of the string.
Example: Chart expressions
Example Result
Index( 'abcdefg', 'cd' ) Returns 3
Index( 'abcdabcd', 'b', 2 ) Returns 6 (the second occurrence of b)
Index( 'abcdabcd', 'b',-2 ) Returns 2 (the second occurrence of b starting from the end)
Left( Date, Index( Date,'-') -1 ) where Date = 1997-07-14 Returns 1997
Mid( Date, Index( Date, '-', 2 ) -2, 2 ) where Date1997-07-14 Returns 07
Index( 'abc', 'x' ) Returns 0 (x does not exist in the string abc)
Index( 'abc', 'a', 2 ) Returns 0 (there is no 2nd occurrence of a)

Example - Index fundamentals

Example - Index scenario

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!