r/excel • u/small_trunks 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.
| Step | Actions |
|---|---|
| 1 | write your "new data" query - probably you have it |
| 2 | Add a step to create a custom column "Comments" and any other columns to keep. =null |
| 3 | Load-to a Table |
| 4 | New query from this new table - name it tblHistoric |
| 5 | Edit the original query (1) |
| 5.1 | remove the custom field step(s) |
| 5.2 | Add a merge step |
| 5.21 | choose whatever columns necessary for a unique row key |
| 5.22 | second query = tblHistoric |
| 5.23 | Left outer join |
| 6 | Expand the returned Table column |
| 6.1 | unselect all except the to be retained columns |
| 6.2 | No column name prefix |
- There's a way to "adopt" self-added columns - but that's a slightly different answer.
- EDIT 20/7/2022 - example download file: https://www.dropbox.com/s/z05fs7wmh7j4zef/SelfRefPQexample.xlsx?dl=1
- EDIT 19/1/2024 - Newer example with more documentation: https://www.dropbox.com/scl/fi/q6eh7mz1xqkt43iv8afzg/SelfRef2.xlsx?rlkey=0re4ekg8u6xpazyu3gzrajd7e&dl=1
- EDIT 5/9/2025 - See the extensive documentation here: https://www.reddit.com/r/excel/comments/ek1e4u/table_updates_via_power_query_whilst_retaining/lzx533y/
132
Upvotes
8
u/Planted_Baker803 Sep 07 '23
u/small_trunks this is a great post! Thanks a lot. I have a similar situation and trying to follow a similar approach. In step 5.1, when we remove the custom fields ('Comments') from the original query, the 'tblHistoric' gives an error, 'Comments' is missing. What am i doing wrong ? Please pardon if its a noon question, I am quite inexperienced in PQ.
4
u/wyldtwyst Feb 01 '24
Thank you so much. I got this working as well.
I'm curious - I have this master list of data that I got this working on, we'll call it Widgets_Master, but I have four other queries I need to run that return a limited result set on their own tabs (i.e. Widgets_Late, Widgets_DueSoon - the filters are a bit more complex than that but I don't think that is relevant?) Is it possible for me to have these queries set up in a way that if the user places comments in one of the four queries that filters the data, that the data can persist back to the master list? I connected my tables in the relationship editor, (Widgets_Master [ID] = Widgets_Late [ID], left outer join) and they are one-to-one relationships. But I can't seem to make it so that if a user is on the table created by the Widgets_Late query and they update the comments, the comments persist back to Widgets_Master. Is this possible?
I am in Excel 2019.
Thank you again for your clearly-written steps. This is very helpful!
3
u/firstcoffees Oct 30 '24
Thanks for posting this. Unfortunately it’s not quite working for me - I am very new to PQ, so it’s definitely user error.
My table won’t retain manually entered data in the “Comments” column, and now it also won’t add in new info from the original source table.
A couple things I didn’t understand from your directions:
Step 5.21 - I just selected all the columns in both queries except for the “comments” column. I’m not sure what you mean by “unique row key”?
Step 6.1 - Should this step just be retaining the manual columns that I did not select in Step 5.21?
Thanks!
2
u/jzee08 Mar 24 '20
Thank you for your quick response! I will try it in about an hour when I get off and I'll let you know the result :)
2
u/Guille3094 Jun 19 '24
I'm so dumb, I couldn't understand this. I need to merge two tables table 1 and table 2. Table 1: Has some tasks to be done. Table 2: has the name of the people responsable for that task.
I want to merged table 2 (to avoid filling the name of the responsable manually) into table 1, and as the tasks change regularly, I need to edit table 1 quite often. I'm like crazy trying to solve this :(, this post is old, but I'm desperate.
2
u/Didoka2 Dec 01 '24
Great post saved me a lot of work. Quick question is there a way to add/remove columns after the self referencing is done. I get the error "[Expression.Error] The field 'total' already exists in the record"
2
u/thaarcher05 Feb 06 '25
Hi, is it possible to do this if the original query is sourced from Power BI?
2
u/crafty_sequoia Apr 28 '25
I have followed the instructions above and added a Comments column to self-reference. But when I refresh the data, all my comments are cleared, so I’m missing something. Just to confirm, I should be able to put the comments into NewDataQuery and they should remain after adding more data and refreshing.
Is there anything else I might be missing?
2
u/Autistic_Jimmy2251 3 Nov 27 '25
u/small_trunks,
I ran into a video on YouTube that explained this same type of process about a year ago. I was never able to get it working. I wish I had found this post back then.
I abandoned that project and won’t be using this approach anytime soon but I think this is extremely valuable info.
May I suggest you consolidate your current knowledge on the subject and repost it in r/ExcelTips?
Seeing as PQ has become much more popular to use in the past 5 years I think many people could benefit from this info where they don’t need to review all the old comments. A fresh look as you would.
15
u/tirlibibi17 Jan 04 '20
Added to the wiki
1
u/KGodvalley Sep 13 '25
Hi and thanks for this. I have been using it several times and it has saved me a lot of manual copying and pasting, and the error proneness that comes with it. However... I have on several occasions managed to break my workbook because I wanted to add a new manually keyed column. I have also managed it on a few occasions, but I am not entirely sure what I do wrong and right. What would you say is the proper way to "infuse" the thing with a new, manual input column that works like the ones I had in the original version, that went through your steps above?
1
u/highvoltageacdc1 Dec 01 '25
This is absolutely brilliant and solves a huge issue for me.
In my case, I want to
In other words, I only want the comment to persist for as long as the row is present in the original query. Is this possible?
1
u/Striking-Novel6525 Dec 14 '25
I have a data table that is linked to power bi via query. On refresh if an account is closed or moved it is removed from power bi and the excel sheets. I have a notes column that I edit for myself to know what I am doing in each account. I need the notes column to to update to the account it is linked in refresh (aka delete when an account is removed or move with an account if the account is moved) is this possible and if so what is the best way to do so?
1
u/[deleted] Oct 07 '23
Hi u/small_trunks, thank you for the good work. I have a question and I'm hoping you can help me out. I followed your steps and it worked; however, I've encountered a small issue: I noticed that when I filter any column in my query, load it, but then decide to remove that step, the comments added disappear. For example, I thought to my self, I only want to see responses under the Austin territory, but then changed my mind and decided that I wanted to see all territories. The comments I had added for other territories disappeared. Have you encountered this issue?
1
u/stoefah Nov 26 '23
Thank you very much for this. Searched for hours on how to do this.
1
u/Equivalent_Run6107 Feb 09 '24
u/small_trunks Sir/Ma'am, you are an angel among men. *chef's kiss*. Thank you for sharing with everyone.
1
u/Decronym Dec 01 '24 edited Jun 08 '26
Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:
Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.
Beep-boop, I am a helper bot. Please do not verify me as a solution.
9 acronyms in this thread; the most compressed thread commented on today has 19 acronyms.
[Thread #39115 for this sub, first seen 1st Dec 2024, 20:05] [FAQ] [Full list] ^[Contact] [Source code]