# Tags
**Software** : [[02 - Tags/Software/Power Query]]
**Functions** used : [[Table.TransformColumnTypes]] [[List.Sum]] [[02 - Tags/Power Query Functions/List.Select]] [[Table.ColumnNames]] [[Text.Contains]] [[list.Accumulate]] [[Table.TransformColumns]] [[Table.Column]] [[Excel.CurrentWorkbook]]
**Date** : 16-March-2025
# Description
Looping in M-query is not as straight forward a with other scripting languages like python. In this tutorial I show you how to iterate and transform columns in a table without repeating the transformation manually.
# Video Link
<iframe width="560" height="315" src="https://www.youtube.com/embed/XV0JrQodY18?si=LqSFc5QYbdWIz2Ub" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
[GITHUB File Link](https://github.com/jbotes/powerbiTutorials/blob/main/PQ_Listaccumulate_video.xlsx)
# M-Query
```mquery
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ChangedType = Table.TransformColumnTypes(Source,{{"Stock Code", type text}, {"Portfolio1", Int64.Type}, {"Portfolio2", Int64.Type}, {"Portfolio3", Int64.Type}, {"Portfolio4", Int64.Type}, {"Portfolio 5", Int64.Type}, {"Portfolio 6", Int64.Type}, {"Portfolio 7", Int64.Type}}),
TransformFunction = Table.TransformColumns(ChangedType, {{"Portfolio1", each _ / List.Sum(ChangedType[Portfolio1])}}),
SelectedColumns = List.Select(Table.ColumnNames(ChangedType), each Text.Contains(_, "Portfolio", Comparer.OrdinalIgnoreCase)),
Custom1 = List.Accumulate(SelectedColumns, ChangedType, (StateTableColumns, CurrentColumn)=> Table.TransformColumns(StateTableColumns,
{{CurrentColumn, each _ / List.Sum(Table.Column(ChangedType,CurrentColumn ) )}}))
in
Custom1
```
## Optional Tags
**Tags** :
**Technique** : [[Looping]]