excelpowerquery

How to auto refresh excel dashboard on file/data modification


I have created a power query in excel which will refresh every 1 hr. But Is it possible to set the refresh properties to refresh the data on data change in the source file ? Thanks in advance.


Solution

  • Excel does not have a built-in feature to automatically refresh Power Query connections directly based on changes in the source file so you can use VBA like in the following example based on the modification date of the file (but keep in mind you can have a new version of your file but with the same data) :

    Private Sub Workbook_Open()
        Application.OnTime Now + TimeValue("00:01:00"), "CheckForChanges"
    End Sub
    
    Sub CheckForChanges()
        Dim lastModifiedTime As Date
        Dim sourceFilePath As String
        
        sourceFilePath = "C:\path\to\your\sourcefile.xlsx"
        
        lastModifiedTime = FileDateTime(sourceFilePath)
        
        If ThisWorkbook.Sheets(1).Range("A1").Value <> lastModifiedTime Then
            ThisWorkbook.Sheets(1).Range("A1").Value = lastModifiedTime
            
            ThisWorkbook.RefreshAll
        End If
    
        Application.OnTime Now + TimeValue("00:01:00"), "CheckForChanges"
    End Sub
    

    https://community.fabric.microsoft.com/t5/Power-Query/VBA-Code-to-Refresh-Power-Query/td-p/2449582

    If you're using Office 365 you can create a new flow with Power Automate to trigger a refresh when the source file changes.

    https://community.fabric.microsoft.com/t5/Power-Query/VBA-Code-to-Refresh-Power-Query/td-p/2449582

    If you are looking for incremental refresh : https://www.youtube.com/watch?v=cxOH9qsDunA