# How to simplify a special combining of two lists into one

#### anvg

##### Active Member
Hi
I need a code for Power Query for a combining of two lists into one
Code:
``````//it is start lists with equal length
listA = {"a","b","c"},
listD = {"1","2","3"},
//it is a needed list
I created a query for this task. It is
Code:
``````let
//start lists A and D
listA = {"a","b","c"},
listD = {"1","2","3"},
//convert list to tables
tableA = Table.FromList(listA),
tableD = Table.FromList(listD),
//change Column1 name to another for a join
renameA = Table.RenameColumns(indexA,{ {"Column1","A"} }),
renameD = Table.RenameColumns(indexD,{ {"Column1","D"} }),
//join tables by enum columns
join = Table.Join(renameA,"IdA",renameD,"IdD")[ [A],[D] ],
//create and return a needed listAD = { {"a","1"},{"b","2"},{"c","3"} }
in
return``````
Is there any way to do my code more simple?
I understand that I can write an udf-function for steps to a join command like this
Code:
``````let
Creator = (inList as list,suffix as text) as table =>
let
toTable = Table.FromList(inList),
changeName = Table.RenameColumns(toTable,{ {"Column1",suffix} }),
in
indexCol
in
Creator``````
But I interest other solve, maybe with list functions.
Many thanks!

### Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

#### Ozeroth

##### Active Member
Here are two ideas :

Code:
``````let
listA = {"a","b","c"},
listD = {"1","2","3"},
in
Code:
``````let
listA = {"a","b","c"},
listD = {"1","2","3"},
()=> [ Position = 0, ItemA = listA{0} , ItemD = listD{0} ],
each [Position] < List.Count(listA),
each [ Position = [Position]+1, ItemA=listA{[Position]+1}, ItemD = listD{[Position]+1} ],
each {[Item1], [Item2]}
)

in

#### anvg

##### Active Member
Excelent! Thank you very much!

each {[Item1], [Item2]} is necessary to correct on {[ItemA], [ItemD]}.

Could I ask you another question? What other iteration varinats has Power Query?

#### anvg

##### Active Member

Thank you very much for your collaboration!

#### ChrisWebb

##### New Member
Here's another option, a bit simpler than using List.Generate():

Code:
``````let
listA = {"a","b","c"},
listD = {"1","2","3"},
listpositions = List.Positions(listA),
output = List.Transform(listpositions, each {listA{_}, listD{_}})
in
output``````
Chris

• ImkeF and Ozeroth

#### anvg

##### Active Member
ChrisWebb, thank you very much!

It was very informative for me.

1,095,168
Messages
5,442,792
Members
405,196
Latest member
rmuir12

### This Week's Hot Topics

• Copy entire row if CountA <>0 to another sheet
[B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
• Select last used Row in Table
I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
• excel workbook: do not allow certain file name
Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
• fixing problem autofilter
hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
• “Weight”
Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
• How to capitalize everything before a certain character?
In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...