Flattens a nested array or extracts property values from an array of objects.
flatten(array)
flatten(arrayOfObjects.property)
| Parameter | Type | Description |
|---|---|---|
array |
Array | The array to flatten or property path to extract |
Array - A flattened array of values.
The flatten function can flatten nested arrays into a single-level array, or extract all values of a specific property from an array of objects. This is essential for preparing data for aggregate functions.
Result = FLATTEN([[1, 2], [3, 4], [5]])
// Result: [1, 2, 3, 4, 5]
// Given AppData.Cities with objects containing 'population' property
Populations = FLATTEN(AppData.Cities.population)
// Result: [39538223, 29145505, 21538187, ...]
// Sum all populations
TotalPopulation = SUM(FLATTEN(AppData.Cities.population))
// Get average of extracted values
AverageScore = AVG(FLATTEN(AppData.Students.score))
- Data extraction: Get property values from object arrays
- Array processing: Flatten nested structures
- Aggregation prep: Prepare data for SUM, AVG, etc.
- Data transformation: Restructure array data
- sum - Sum flattened values
- avg - Average flattened values
- objectkeystoarray - Extract object keys
- objectvaluestoarray - Extract object values
- Critical for preparing data for aggregate functions
- Works with both nested arrays and object arrays
- Uses the Math service's
flattenmethod - Commonly used in data pipelines