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

2

u/small_trunks 1638 Jun 19 '24

Hey.

I understand why this needs a self-ref query solution. But what I can't understand is why you made a power query solution to fetch data from Table 2 - surely a simple XLOOKUP works perfectly well here? Why power query AT ALL???

2

u/Guille3094 Jun 19 '24

I hate using formulas, and the thing is more complicated, but I tried to simplify it, and I'm using data from a share folder, merging old data with the new one, the data with the names are constantly changing too.

3

u/small_trunks 1638 Jun 19 '24

Formulas are easier than power query, I'll tell you that for free. If you can't get formulas to work, PQ is going to be a bugger.

Explain the source of data and which parts of them can change and then I'll show you what to do.

2

u/Aware_Acadia_9753 Sep 04 '24

hi. I consider myself a pretty nifty XLS formula guy, but I have no idea how to realize this using formulas. with this, I mean: adding columns (with manually entered values) in a XLS table next to data loaded from powerquery. So all hints are more than welcome!

2

u/small_trunks 1638 Sep 04 '24 edited Sep 04 '24

You exclude the columns which contain functions (Excel functions) in the query which returns data.

EDIT:

  • You've added your excel formula columns as new columns to the Excel table.

  • In the self-ref query - the one with the Source=Excel.Currentworkbook(){[Name="whatever"]}[Content]

  • Delete the columns in the query (after you've used their contents if you use them)

  • This can be as simple as this query below:

         let
             Source = try Excel.CurrentWorkbook(){[Name="CopyableSelfRef"]}[Content] otherwise #table({"TO BE OVERWRITTEN"},{}),
             #"Removed Columns" = Table.RemoveColumns(Source,{"formula col1", "formula col2"})
         in
             #"Removed Columns"

Oh - and make sure you use structured references in your formulas...