where() Function

Returns the indices where the values in the input array are true.

Syntax

where( booleanArray, [default] )

booleanArray: (Boolean Array) The array of Boolean values to test.

default: (Integer or Integer Array) The integer number or array of integer numbers to return if none of the values in the array are true.

Returns

Integer Array

Notes

If a default value is not specified and none of the values in the input array are true, an empty list will be returned.

This function can be useful for finding the value of one field of a CDT in an array of CDT values where each item in the array has a given value for another field. The default parameter can be used to return a value that is not a valid index in order to cause the index() function to return its default value if none of the values in the input to the where() function are true.

A null or empty array given as the array parameter is considered false.

Examples

You can experiment with this function in the test box below.

Test Input

where({true, false, true}) returns 1, 3

where(mod({13, 24, 35, 46, 57, 68}, 2)=0) returns 2, 4, 6

Use with Comparison Operators:

where(pv!scores<50) returns 8, 10, 12 where pv!scores = {68, 89, 82, 90, 93, 99, 59, 49, 88, 27, 56, 49, 100}

where(pv!scores>avg(pv!scores)) returns 2, 3, 4, 5, 6, 9, 13 where pv!scores = {68, 89, 82, 90, 93, 99, 59, 49, 88, 27, 56, 49, 100}

where({pv!scores}<average({pv!scores})-3*stdevp({pv!scores}),-1) returns -1 where pv!scores = {68, 89, 82, 90, 93, 99, 59, 49, 88, 27, 56, 49, 100} because no scores are 3 standard deviations less than the mean and -1 is given as the default value to return if none of the items in the array are true

Use with the index() Function:

index(pv!employees.firstName, where(like(pv!employees.department, "Finance"), -1), "None") returns all of the first names of employees in the Finance department, or "None" if none of the employees have their department field set to Finance.

Use with a Null or Empty Array:

where(null, 1000) returns 1000

where(null) returns an empty list

where({}, -1) returns -1

where({}) returns an empty list

where({true, false, null, true}) returns 1, 4

See Also

wherecontains(): Use this function to return indices of an array that match a user-defined value, instead of items that evaluate to true.

index(): Use this function to return the values of an array at the indices you gathered with the where() function.

FEEDBACK