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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sendilc
Frequent Visitor

Adding columns dynamically based on availability

Hi, 

I have a situation where I need to add columns dynamically if the column is not available. Say for e.g. I have 4 predefined columns [A, B, C, D] and I have a table "Data" with columns [Sno, Date, B, D]. 

Now I want to iterate to check if [A,B,C,D] all predefined columns are available in table "Data", I am trying to use accumulate to find out if it can be achieved in the below fashion or is there a better way to solve this issue. 

 

= List.Accumulate({"A","B","C","D"}, "Data"}, Table.ColumnNames(#"Data"),
(original, current) =>

if !(Table.Hascolumns[current],original) then  

     Table.AddColumn(original,current[], each [current]))

 

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @sendilc ,

 

I'd just predefine all the columns that should be present in a blank table, then append the actual imported table onto it.

Here, Chris Webb explains it better than me:

https://blog.crossjoin.co.uk/2015/07/03/ensuring-columns-are-always-present-in-a-table-returned-by-p... 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
sendilc
Frequent Visitor

Thanks @BA_Pete this helps... I was able to solve the issue. 

BA_Pete
Super User
Super User

Hi @sendilc ,

 

I'd just predefine all the columns that should be present in a blank table, then append the actual imported table onto it.

Here, Chris Webb explains it better than me:

https://blog.crossjoin.co.uk/2015/07/03/ensuring-columns-are-always-present-in-a-table-returned-by-p... 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors