Introduction to iteration
Iteration is a core concept in programming, important for performing repetitive actions on data. In Power Query, iteration often happens over rows in a table or items in a list.
Suppose you want to square a list of 1,000 numbers. Doing this without iteration would require writing 1,000 separate lines of code, which is both time-consuming and error-prone. With iteration, the same task can be completed with just a few lines of code.
Traditional languages like Python or Java use for
and while
loops for such tasks. However, the Power Query M language takes a different approach to iteration. It performs transformations on its underlying data structures by design.
For example, when you use Table.AddColumn
to create a new column, Power Query automatically applies the specified operation to each row in the table, similar to how a for
loop would iterate over each element in a list. The M language automatically does the iteration for you using its standard...