Forum Discussion
[PowerQuery] Function to add columns based on a list of column names
- 5 years ago
Here is the solution I found. (May be helpfull for others)
let myFunc = ( myTable, myNewColumnList) =>
let foo = List.Accumulate(
myNewColumnList,
myTable,
(current_table, new_name) =>if List.Contains(Table.ColumnNames( current_table), new_name)
then current_table
else Table.AddColumn(current_table, new_name, each null))
in foo
in myFunc
Here is the solution I found. (May be helpfull for others)
let myFunc = ( myTable, myNewColumnList) =>
let foo = List.Accumulate(
myNewColumnList,
myTable,
(current_table, new_name) =>
if List.Contains(Table.ColumnNames( current_table), new_name)
then current_table
else Table.AddColumn(current_table, new_name, each null)
)
in foo
in myFunc
Hi, I am trying to add value to the added column based on a condition. But it's failing with the message: "Expression.Error: The name 'current_table' wasn't recognized. Make sure it's spelled correctly." Would you please provide some insight?
let myFunc = ( myTable, myNewColumnList, V1) =>
let foo = List.Accumulate(
myNewColumnList,
myTable,
(current_table, new_name) =>
if List.Contains(Table.ColumnNames(current_table), new_name)
then current_table
else
let
condition = if new_name = V1 then V1 else "excluded"
in condition ,
Table.AddColumn(current_table, new_name, condition)
)
in foo
in myFunc