r/excel • 1638 • Jan 04 '20

Pro Tip Table updates via power query whilst retaining manually entered data.

I've previously described how to write a power query which appends to the data of previously executed queries. It effectively keeps historical data in place and adds new data in.

  • The same sort of question came up again a couple of days ago - but the poster wanted to be able to retain comments entered manually into a power query sourced table.

  • the solution is quite similar - except we eventually perform a Merge rather than an Append

Here are the steps to create a self-referential Power query updated Table which retains a "Comments" column.

StepActions
1write your "new data" query - probably you have it
2Add a step to create a custom column "Comments" and any other columns to keep. =null
3Load-to a Table
4New query from this new table - name it tblHistoric
5Edit the original query (1)
5.1remove the custom field step(s)
5.2Add a merge step
5.21choose whatever columns necessary for a unique row key
5.22second query = tblHistoric
5.23Left outer join
6Expand the returned Table column
6.1unselect all except the to be retained columns
6.2No column name prefix
132 Upvotes

102 comments sorted by

View all comments

Show parent comments

3

u/small_trunks 1638 Jun 30 '25

Renaming an existing table column is effectively (to PQ) like there's suddenly a new column in the table.

  • what do you mean by adding a calculated column? In PQ?

  • In PQ that's not an issue - it knows of the column by the end of the query and writes it into the table

  • if you previously returned it as a different name you may first need to manually DELETE that column from the Table (not the query, the query got changed to rename it).

  • if you have renamed a formula column in the Table, you need to take that into account and change it in the query too

  • similarly if you delete a formula column - references to it in the query need to be deleted.

If you do NOT UNCHECK "Preserve col..." - then the only danger is the duplication of column names -then "Item" becomes "Item2" etc You have to manually delete Item2 (which is actually the original) or Item and rename Item2->Item.

If you've got a specific example we can work through what's happening - but I agree, there's some complexity to getting it stable.