Forum Discussion
Anonymous
2 years agoNot applicable
transform a column for use as array in other PowerQuery commands
Hi, I have an excel where power query does some manipulations. The idea is that I provide a certain table, where the user can create a "mapping", for example: In this table, NR: the sort...
spinfuzer
2 years agoSolution Sage
You can use List.Generate. It can create a list of anything you put in the 4th argument. In this case you want a list of lists. You need to change your types though to match Text.Type and such. I am going to the #shared records and then finding the name that matches Text.Type and then taking the value. I am not sure of any other way to convert the text into a Type. Below is how to change the column types. Changing column names is pretty much the same except you don't need the shared table.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
shared_table = Table.Buffer(Record.ToTable(#shared)),
change =
List.Generate(
() => [n = 0], // iterator
each [n] < Table.RowCount(DATADEF), // end condition
each [n = [n] + 1], // next iterator
each { DATADEF[DATADEF]{[n]}, Table.SelectRows(shared_table, (r) => r[Name] = DATADEF[TYPE]{[n]}){0}[Value]}
) // optional output if iterator is not the desired output
,
transform = Table.TransformColumnTypes(Source, change )
in
transform