Skip to main content

FieldIndex - script and chart function

FieldIndex() returns the position of the field value value in the field field_name (by load order).

Syntax:  

FieldIndex(field_name , value)

Return data type: integer

Arguments:  

  • field_name: Name of the field for which the index is required. For example, the column in a table. Must be given as a string value. This means that the field name must be enclosed by single quotes.
  • value: The value of the field field_name.

Limitations:  

  • Sorting on y-values in charts or sorting by expression columns in tables is not allowed when this chart function is used in any of the chart's expressions. These sort alternatives are therefore automatically disabled. When you use this chart function in a visualization or table, the sorting of the visualization will revert back to the sorted input to this function. This limitation does not apply to the equivalent script function.

  • If value cannot be found among the field values of the field field_name, 0 is returned.

Examples:  

Add the example data below to your document and run it. The following examples use the field: First name from the tableNames.

Examples and results
Example Result

Chart function - in a table containing the dimension First name, add as a measure:

FieldIndex ('First name','John')

1, because 'John' appears first in the load order of the First name field. Note that in a list box John would appear as number 2 from the top as it's sorted alphabetically and not as in the load order.

Chart function with First name:

FieldIndex ('First name','Peter')

4, because FieldIndex() returns only one value, that is the first occurrence in the load order.

Script function - given the table Names is loaded, as in the example data:

John1:

Load FieldIndex('First name','John') as MyJohnPos

Resident Names;

MyJohnPos=1, because 'John' appears first in the load order of the First name field. Note that in a list box John would appear as number 2 from the top as it's sorted alphabetically and not as in the load order.

Script function with Names:

Peter1:

Load FieldIndex('First name','Peter') as MyPeterPos

Resident Names;

MyPeterPos=4, because FieldIndex() returns only one value, that is the first occurrence in the load order.

Data used in example:

Names:

LOAD * inline [

"First name"|"Last name"|Initials|"Has cellphone"

John|Anderson|JA|Yes

Sue|Brown|SB|Yes

Mark|Carr|MC |No

Peter|Devonshire|PD|No

Jane|Elliot|JE|Yes

Peter|Franc|PF|Yes ] (delimiter is '|');

 

John1:

Load FieldIndex('First name','John') as MyJohnPos

Resident Names;

 

Peter1:

Load FieldIndex('First name','Peter') as MyPeterPos

Resident Names;

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!

Join the Analytics Modernization Program

Remove banner from view

Modernize without compromising your valuable QlikView apps with the Analytics Modernization Program. Click here for more information or reach out: ampquestions@qlik.com