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 |
---|---|
|
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. |
|
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 |
Chart function: In a table containing the dimension |
|
FieldIndex ('First name','John') |
1, because ' |
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 |
|
John1: Load FieldIndex('First name','John') as MyJohnPos Resident Names; |
MyJohnPos=1, because ' |
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;