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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Add column if not exists

Hi community,

 

once again I have encountered a "challenge":
I have a master file based on several Excel files. These files are all located in one folder and are retrieved via power-query (get data > from file > from > folder). Every month, different departments file their current reports here.

Since last month, it has been decided that the future reports from each department should contain an additional column containing the project type. If these "extended" reports are now stored in the folder and the master file is updated, an error will appear.

 

Ma_har_0-1592919089005.png

 

My idea now is to add a conditional column in the sample file (in the power editor) in the right place for all files which do not have the column "project type" yet.
So all files would have the same columns.

 

So far I have difficulties to add this conditional column at the right place. Are there already approaches or maybe even better ideas?

I am glad about every support.

 

 

Best regards

 

 

1 ACCEPTED SOLUTION

hi  @Anonymous 

You may refer to this post:

https://community.powerbi.com/t5/Desktop/Add-a-new-column-to-the-existing-data-set-and-refresh/m-p/116592

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Look at Table.ColumnCount

https://docs.microsoft.com/en-us/powerquery-m/table-columncount

 

or Table.ColumnNames

https://docs.microsoft.com/en-us/powerquery-m/table-columnnames

 

to see if the column is present or not.  Based on that you can then modify your subsequent Table.SelectColumns call.

 

 

@Anonymous how you are appending files together? You can check the missing column name in the file and then add it conditionally something like this.

 

=if List.Count(List.FindText(Table.ColumnNames( <<your previous step>> ), "ColumnName" ))= 1 then <<previous step>> else Table.AddColumn(<<previous step>>, "ColumnName", each "", type text)

 

it basically checks if a column name already exists, if yes do nothing otherwise add new column.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k ,

 

Sorry, I'm still in the training phase of Power Editor.
Is that code you would write in a custom column or in Advanced Editor?

 

 

hi  @Anonymous 

You may refer to this post:

https://community.powerbi.com/t5/Desktop/Add-a-new-column-to-the-existing-data-set-and-refresh/m-p/116592

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors