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:  

Argument Description
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:  

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

Examples and results:  

The following examples use the field: First name from the tableNames.

Examples Results

Add the example data to your app and run it.

The table Names is loaded, as in the sample data.

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 filter pane John would appear as number 2 from the top as it's sorted alphabetically and not as in the load order.

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 filter pane John would appear as number 2 from the top as it's sorted alphabetically and not as in the load order.

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!