TableFilterByRowFunction
Filters a table of data or array using the provided Lambda Function applied to each row.
Syntax
TableFilterByRowFunction(Input Array, Filter Function, [Include Header Row])
Where:
Input Array is the array to iterate over.
Filter Function if the result of this function is TRUE, it will be included in the result.
Include Header Row (optional) if true, the header will be included in the filter.
- Input Arrays are assumed to include a header row by default. Set this argument to TRUE if the Input Array does not have a header row.
Filter Function
Please see Higher Order Functions for more information on this type of function.
The DWLambda used for the filter function uses the following syntax:
DWLambda(dataRow, [rowIndex], Function)
dataRow is the row from the Input Array to be evaluated.
- When the Input Array is parsed each dataRow is passed to the function.
- dataRow is a required parameter in the Function Argument.
rowIndex (optional) is the index of the row currently being evaluated.
- When the Input Array is parsed the index of each row is passed to the function.
- Using the dataRow in the Function argument is optional.
- The Filter Function will not retrieve values from the header row. A rowIndex of 1 will refer to the first data row, which is the first row after the header row or the first row in a table with no headers (in which case Include Header Row must be set to TRUE).
Function is the Lambda function to be executed.
Use Rules Insight to insert the required lambda signature into the function.
Examples
Example 1
This example filters a table based on a comparison of values found in two cells of each row.
Rule
TableFilterByRowFunction(
DwLookupBeamSizesSy,
DWLambda(
dataRow,
TableGetValue(dataRow,3,1)*100<TableGetValue(dataRow,2,1)
)
,FALSE
)
Result
The result is a new array that only includes rows where the value in cell 3, multiplied by 100, is less than the value in cell 2.
Viewed as an array:
{"Size","Sy","WT","W";"W27 x 178","78.8","0.725","14.1";"W27 x 146","63.5","0.605","14";"W21 x 147","60.1","0.59","11";"W21 x 101","51.2","0.5","9.5"}
Viewed as a table:
| Size | Sy | WT | W |
|---|
| W27 x 178 | 78.8 | 0.725 | 14.1 |
| W27 x 146 | 63.5 | 0.605 | 14 |
| W21 x 147 | 60.1 | 0.59 | 11 |
| W21 x 101 | 51.2 | 0.5 | 9.5 |
Data (Table named BeamSizesSy)
The original table containing the array to be filtered.
| Size | Sy | WT | W |
|---|
| W27 x 178 | 78.8 | 0.725 | 14.1 |
| W27 x 161 | 65.9 | 0.66 | 14 |
| W27 x 146 | 63.5 | 0.605 | 14 |
| W27 x 114 | 31.5 | 0.57 | 10.1 |
| W24 x 55 | 8.3 | 0.44 | 10 |
| W21 x 147 | 60.1 | 0.59 | 11 |
| W21 x 132 | 53.5 | 0.58 | 11 |
| W21 x 101 | 51.2 | 0.5 | 9.5 |
| W21 x 93 | 22.1 | 0.48 | 9.5 |
| W21 x 83 | 19.5 | 0.47 | 9 |
| W21 x 57 | 9.4 | 0.38 | 8 |
Example 2
This example filters a table based on a comparison of values found in two cells of each row, and conditionally include a given row.
Rule
TableFilterByRowFunction(
DwLookupBeamSizesSy,
DWLambda(
dataRow,
rowIndex,
If(
rowIndex=11,
TRUE,
TableGetValue(dataRow,3,1)*100<TableGetValue(dataRow,2,1)
)
),FALSE
)
Result
The result is a new array that only includes rows where the value in cell 3, multiplied by 100, is less than the value in cell 2. Row 11 is included regardless of this match.
Viewed as an array:
{"Size","Sy","WT","W";"W27 x 178","78.8","0.725","14.1";"W27 x 146","63.5","0.605","14";"W21 x 147","60.1","0.59","11";"W21 x 101","51.2","0.5","9.5";"W21 x 57","9.4","0.38","8"}
Viewed as a table:
| Size | Sy | WT | W |
|---|
| W27 x 178 | 78.8 | 0.725 | 14.1 |
| W27 x 146 | 63.5 | 0.605 | 14 |
| W21 x 147 | 60.1 | 0.59 | 11 |
| W21 x 101 | 51.2 | 0.5 | 9.5 |
| W21 x 57 | 9.4 | 0.38 | 8 |
Data (Table named BeamSizesSy)
The original table containing the array to be filtered.
The row with index 11, included by the rule, has been highlighted.
| Size | Sy | WT | W |
|---|
| W27 x 178 | 78.8 | 0.725 | 14.1 |
| W27 x 161 | 65.9 | 0.66 | 14 |
| W27 x 146 | 63.5 | 0.605 | 14 |
| W27 x 114 | 31.5 | 0.57 | 10.1 |
| W24 x 55 | 8.3 | 0.44 | 10 |
| W21 x 147 | 60.1 | 0.59 | 11 |
| W21 x 132 | 53.5 | 0.58 | 11 |
| W21 x 101 | 51.2 | 0.5 | 9.5 |
| W21 x 93 | 22.1 | 0.48 | 9.5 |
| W21 x 83 | 19.5 | 0.47 | 9 |
| W21 x 57 | 9.4 | 0.38 | 8 |
See Also
Higher Order Functions - About higher order functions.
DWLambda - Allows custom, reusable functions to be created.
TableMap - Applies a Lambda Function across a provided array and returns a new array with the result of the Lambda function applied.
TableFilterByFunction - Filters an array based on a single column using the provided Lambda Function.