Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hello everyone,
I would like to create a function that do the following :
Given 2 parameters :
- A table
- A list of name for new columns. Ex: {"COUNTRY", "CUSTOMER_NAME"}
Return : The input table with new columns. The added columns should be created if they do not already exist in the input table. Their types should be Text, and values should be null.
How can I do that ?
(My thought is that using List.Accumulate might be a good starting point... but can't see how to go further)
Thanks
Regards
Solved! Go to Solution.
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
How many NULL values do you need in each row of the columns? Can you take the column and pivot it, to make the list into columns?
I added a custom column which is just blank (null)
Then hit "pivot column" whilst having the List highlighted:
And then I get the following:
It doesn't quite get you 'NULL' but gets the column names, and then adding new rows to that list will automatically add new columns.
I am confused, did you just copy my answer over or were you trying to reply to it?
How many NULL values do you need in each row of the columns? Can you take the column and pivot it, to make the list into columns?
I added a custom column which is just blank (null)
Then hit "pivot column" whilst having the List highlighted:
And then I get the following:
It doesn't quite get you 'NULL' but gets the column names, and then adding new rows to that list will automatically add new columns.
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