Power BI: merge tables automatically by loading them

In some projects, I have to load new data each month and merge those new ones to the old one so every month, I have to repeat the same process manually which is to load it then to append it in Power Query Editor. The idea is to make it more automatic so my goal is just to load the data and to forget about the rests.

First thing I have to do, it is to create a default table with no data, just the header. It is my main table in which I will do everything. For that, I will click on “home -> enter data”:

power bi

For my article, I will create it with 2 columns only (those columns should match exactly with all the future tables):

power bi power bi

This is the result:

power bi

I will click on “home -> transform data -> transform data” to go to Query Editor:

power bi

Click on “home -> advanced editor”:

power bi

The code looks like that:

power bi

For each new table, I will add this code:

TableToAppend1 = try XXX otherwise null,
#"Result1" = if TableToAppend1 <> null then Table.Combine({#"YYY", TableToAppend1}) else #"YYY"

NOTE:

  • Replace XXX by your table name and YYY by the previous step name
  • Don’t forget to add a comma at the end of the step (the red section in the picture)

For instance:

  • For 1 new table:
    power bi
  • For 2 new tables:
    power bi

No matter how many new tables I will add in my code, the result will always like that:

power bi

If I load my new table called “Table1” and refreshing “Table”, the data will show:

power bi

Now, loading the new table “Table2” and refreshing “Table”:

power bi

The disadvantage is that there is no an easy way to delete “Table1” and/or “Table2” if I don’t need them, I get this message if I do it:

power bi

To delete it, I have to go back to the “advanced editor” and remove its section:

power bi

Then I can delete properly the table and to reset everything, I have to put back as the beginning:

power bi

Interesting Topics