Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hi there,
I was hoping someone could help me with looping in powerbi.
Logic is as follows -
I have columns with supervisors as shown -
The custom column collates all the supervisors.
Currently it is done with simple if statements -
= Table.AddColumn(#"Reordered Columns", "Supervisors", each if([Supervisor 3]<>null) then [Supervisor 1] & " , " & [Supervisor 2] & " , " & [Supervisor 3]
else if([Supervisor 2]<>null) then [Supervisor 1] & " , " & [Supervisor 2]
else [Supervisor 1])
The thing is, this table is based off a column supervisor no. that was pivoted. If the database adds in an extra supervisor - i.e. Supervisor 4, when pivoted there will be an extra column and will throw an error with this calculation.
I would like a loop to dynamically calculate this concatenation so that I do not need to go in and manually change the code if there exceeds the amount of existing supervisors.
Thinking something along the times where there is another custom column specifying number of supervisors then looping through and appending.
Any ideas would be largely appreciated.
Many Thanks,
Ashling
Solved! Go to Solution.
= Table.AddColumn(#"Reordered Columns", "Supervisors", each Text.Combine(Record.ToList(Record.SelectFields(_,List.Select(Record.FieldNames(_),each Text.StartsWith(_,"Supervisor")))),", "))
this will combine all the columns that starts with Supervisor
= Table.AddColumn(#"Reordered Columns", "Supervisors", each Text.Combine(Record.ToList(_),","))
Thanks - it is more efficient to be -
= Table.AddColumn(#"Reordered Columns", "Supervisors", each Text.Combine({[Supervisor 1],[Supervisor 2],[Supervisor 3]},", "))
although not sure how to pass in those columns dynamically using Record.ToList?
= Table.AddColumn(#"Reordered Columns", "Supervisors", each Text.Combine(Record.ToList(Record.SelectFields(_,List.Select(Record.FieldNames(_),each Text.StartsWith(_,"Supervisor")))),", "))
this will combine all the columns that starts with Supervisor
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 14 | |
| 12 | |
| 10 | |
| 7 | |
| 6 |