Iterate table columns in PowerBI data transformation
PowerBI applies a lot of functions automatically or you can make them manually. But if you work with a dynamically changed data, for example, when new columns are added in SharePoint list, and you don’t want to add them manually every month (week, year, etc), you can automatically iterate through them.
In Power BI, the Power Query Editor allows you to transform and clean your data using a language known as "M." But there are no classic cycles like 'for', 'while' or something like this, you should use other tools.
Power BI applies a lot of functions automatically or you can make them manually. But if you work with a dynamically changed data, for example, when new columns are added in SharePoint list, and you don’t want to add them manually every month (week, year, etc), you can automatically iterate through them.
In the example below I remove all the columns from the SharePoint list data source except Title and columns, which contain CAGR in the title:
= Table.SelectColumns(
#"datasource",
List.Select(
Table.ColumnNames(#"datasource"),
each Text.Contains(_, "Title") or Text.Contains(_, "CAGR")
)
)