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. 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 example uses two fields: First name and Initials.
First name | Initials |
---|---|
John | JA |
Sue | SB |
Mark | MC |
Peter | PD |
Jane | JE |
Peter | PF |
Examples | Results |
---|---|
Chart function, as measure in a table |
|
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, as dimension in a table |
|
Given the table Initials is loaded, as in the sample data: John1: Load FieldIndex('First name','John') as MyJohnPos Resident Initials; |
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. |
Given the tableInitials is loaded, as in the sample data: Peter1: Load FieldIndex('First name','Peter') as MyPeterPos Resident Initials; |
MyPeterPos=4, because FieldIndex() returns only one value, that is the first occurrence in the load order. |
Data used in example:
Initials:
LOAD * inline [
"First name"|Initials|"Has cellphone"
John|JA|Yes
Sue|SB|Yes
Mark|MC |No
Peter|PD|No
Jane|JE|Yes
Peter|PF|Yes ] (delimiter is '|');
John1:
Load FieldIndex('First name','John') as MyJohnPos
Resident Initials;
Peter1:
Load FieldIndex('First name','Peter') as MyPeterPos
Resident Initials;