Flow Control
slug: step-foreachIteratively executes a series of steps for each value in a specified collection, enabling batch processing, multi-scenario analysis, and automated workflows. Acts as a dynamic loop mechanism for repetitive data processing tasks.
At least one of:
values (array) - Explicit list of values to iterate throughcolumn (string) - Column name to extract unique values fromPlus:
steps (array) - Step definitions to execute for each valuevarName (string) - Name of the variable to set for each iteration (default: item)item) with the current value$item or ${varName}forEach:
values: [2023, 2024, 2025]
varName: year
steps:
- filter:
where: "transaction_year = ${year}"
- cube:
dimensions: [region, product_category]
measures: [revenue, units_sold]
- print:
title: "Sales Report - ${year}"
- export:
filename: "sales_${year}.xlsx"
forEach:
column: product_category
varName: category
steps:
- filter:
where: "product_category = '${category}'"
- sort:
by: ["-revenue"]
- calculate:
assign:
category_rank: "$rank"
category_share: "$revenue / $total_revenue * 100"
- chart:
type: bar
x_axis: product
y_axis: revenue
title: "Revenue by Product - ${category}"
Generate individual reports for each business segment:
forEach:
column: segment
varName: segment
steps:
- filter:
where: "segment = '${segment}'"
- cube: { /* segment analysis */ }
- chart: { /* segment visualization */ }
- export:
type: pdf
filename: "${segment}_report.pdf"
Run the same analysis with different parameters:
forEach:
values: [7, 14, 30, 90]
varName: days
steps:
- timeSeries:
date_field: transaction_date
operations:
- type: sma
column: revenue
period: ${days}
- chart:
type: line
x_axis: transaction_date
y_axis: "revenue_sma_${days}"
title: "${days}-Day Moving Average"