Power Query Problems

Record Refreshed Financial Data in Excel with Power Query

Tauseeq MagsiTauseeq Magsi Nov 25, 2026 870 views

Question details

The user wants to retain each scheduled refresh of financial data in Excel as a timestamped historical record.

Record Refreshed Financial Data in Excel with Power Query
Product
Microsoft Excel Power Query
Device & OS
not provided
Scenario
A financial data source refreshes at regular intervals, and each result needs to be saved separately.
Observed behavior
Refreshing the query updates the current result, so earlier values are not automatically preserved.
Before you start

Load the Power Query result to an Excel worksheet table and note the sheet and table names. Create an empty sheet named History, and make sure you can enable trusted macros in the workbook.

Solution 1Recommended

Append each query refresh to a history sheet with VBA

Use this method when the query is loaded to a worksheet table that exposes a working QueryTable refresh event.

This example appends every row of the refreshed table to History and adds a timestamp. It uses the QueryTable AfterRefresh event, not a Worksheet_AfterRefresh event.

Event support can vary by connection and Excel version. Test the event with your query; if it does not fire after a successful refresh, use manual snapshots or another logging method.

1
Set the refresh interval

Open Data > Queries & Connections, right-click the query, and open Properties. On the Usage tab, enable Refresh every and enter the desired interval, such as 5 minutes.

2
Create the event handler

Press Alt+F11, choose Insert > Class Module, and name the class CRefreshLogger in the Properties pane. Paste this code into the class: Public WithEvents TrackedQuery As Excel.QueryTable Public SourceTable As Excel.ListObject Private Sub TrackedQuery_AfterRefresh(ByVal Success As Boolean) Dim logSheet As Worksheet Dim nextRow As Long Dim rowCount As Long Dim columnCount As Long If Not Success Then Exit Sub If SourceTable.DataBodyRange Is Nothing Then Exit Sub Set logSheet = ThisWorkbook.Worksheets("History") rowCount = SourceTable.DataBodyRange.Rows.Count columnCount = SourceTable.DataBodyRange.Columns.Count If logSheet.Range("A1").Value = "" Then logSheet.Range("A1").Value = "Timestamp" logSheet.Cells(1, 2).Resize(1, columnCount).Value = SourceTable.HeaderRowRange.Value End If nextRow = logSheet.Cells(logSheet.Rows.Count, 1).End(xlUp).Row + 1 logSheet.Cells(nextRow, 1).Resize(rowCount, 1).Value = Now logSheet.Cells(nextRow, 1).Resize(rowCount, 1).NumberFormat = "yyyy-mm-dd hh:mm:ss" logSheet.Cells(nextRow, 2).Resize(rowCount, columnCount).Value = SourceTable.DataBodyRange.Value End Sub

3
Connect the handler to the table

In the VBA editor, choose Insert > Module and paste the code below. Replace DataSheet and QueryTable1 with the actual worksheet and table names: Public Recorder As CRefreshLogger Public Sub StartRecorder() Set Recorder = New CRefreshLogger Set Recorder.SourceTable = ThisWorkbook.Worksheets("DataSheet").ListObjects("QueryTable1") Set Recorder.TrackedQuery = Recorder.SourceTable.QueryTable End Sub

4
Start logging when the workbook opens

In the VBA project, double-click ThisWorkbook and add: Private Sub Workbook_Open() StartRecorder End Sub Save the file using File > Save As and select Excel Macro-Enabled Workbook (*.xlsm). Reopen it and enable macros, or run StartRecorder from Developer > Macros to initialize the handler in the current session.

5
Test the history

Use Data > Refresh All, then check the History sheet for timestamped rows. Refresh again and confirm that new rows are appended rather than replacing the first snapshot.

Append each query refresh to a history sheet with VBA
Keep the workbook open: The refresh interval and VBA event require Excel to be running with the workbook open and macros enabled. This method does not recover results from before logging began.
Free Microsoft Office alternative

Review financial data in WPS Spreadsheet

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Excel formats, making it easy to move existing workbooks for everyday viewing and editing. It does not fix Excel Power Query refresh events.

Review and organize financial data in WPS SpreadsheetOpen and edit Microsoft Excel XLSX and XLS filesNavigate a familiar interface when moving from ExcelUse a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Does Power Query keep previous refresh results automatically?

A refresh normally updates the current query output rather than creating a historical log. Append snapshots to another sheet using a working refresh event or copy and paste values manually.

Why is nothing being added to the History sheet?

Check that macros are enabled, StartRecorder has run, and the worksheet, table, and History sheet names match the VBA code. Use Data > Refresh All to test; some connections or Excel versions may not trigger the QueryTable event.

Will the query refresh while the workbook is closed?

The workbook's refresh interval and VBA event do not run while the workbook is closed. An unattended process requires a separate scheduling and logging solution.

Why do I need to save the workbook as an XLSM file?

The refresh logger uses VBA, so choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) to retain the code.