Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
JulianaMacedo
Helper II
Helper II

Iterating over a list in Power Query

Hi everyone, I'm having difficults getting the results I'm willing...

I have a table with a colum that is a result of invoking a function and it gives a list as a result, now I need to iterate over this list and create another column that will give a list a result.

 

= Table.AddColumn(#"Renamed Columns1", "Test", each
let list = [column1]
in 
List.Transform(list, each
if List.Contains(list,0) then "X6"
else if List.Contains(list,1) then "X7"
else if List.Contains(list,2) then "X14"
else if List.Contains(list,3) then "X15"
else if List.Contains(list,4) then "X22"
else if List.Contains(list,5) then "X23"
else if List.Contains(list,6) then "X30"
else if List.Contains(list,7) then "X31"
else "")
)

 

This is what I'm doing now, the problem is that it is giving me the right number of things that should be contained in the list as the result, but it is not iterating correctly.

 

For example, is the list contained in the Column1 has 2 numbers let's say 4 and 7, the resulting list brings me two results in the new list but only takes in account the first number.

let's say the list is like this {4,7}...what I want as a result is a new list in a the new column {X22, X31}. Instead, what I'm getting is {X22,X22}.

Any idea what I'm doing wrong here?




 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this

= Table.AddColumn(#"Renamed Columns1", "Test", each
let list = [column1]
in 
List.Transform(list, (a)=>
if a=0 then "X6"
else if a=1 then "X7"
else if a=2 then "X14"
else if a=3 then "X15"
else if a=4 then "X22"
else if a=5 then "X23"
else if a=6 then "X30"
else if a=7 then "X31"
else "")
)

View solution in original post

2 REPLIES 2
JulianaMacedo
Helper II
Helper II

Awesome! Thanks... I knew it was close, it perfectly worked.

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this

= Table.AddColumn(#"Renamed Columns1", "Test", each
let list = [column1]
in 
List.Transform(list, (a)=>
if a=0 then "X6"
else if a=1 then "X7"
else if a=2 then "X14"
else if a=3 then "X15"
else if a=4 then "X22"
else if a=5 then "X23"
else if a=6 then "X30"
else if a=7 then "X31"
else "")
)

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.