Power Query: Keeping it Current – Part 2
13 July 2022
Welcome to our Power Query blog. This week, I start to convert the query to look for data in the current workbook.
In Power Query: Sheets Ahead – Part 1, I uploaded data from multiple sheets into another workbook. I had some simple monthly data:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image1-1656934216.png/3249abeb14f353251598037c379f8cd0.jpg)
This sheet is for January; I had a similar sheet in the same workbook for February:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image2-1656934192.png/9df3164243f5c90afb4410bb5ef15f65.jpg)
I created a query that not only concatenated this data, but also included the sheets for other months as they appeared if I refreshed it. This query was in a separate workbook:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image3-1656934253.png/d5316f5de32001c015e0e99822625645.jpg)
Last week, I copied this query to the original workbook containing the source data:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image4-1656934368.png/b46349a2f25e1f7d22fa8240effcfbe2.jpg)
The message is telling me the query can’t access the workbook because I have it open. This is true since it is this workbook. However, I have the M code, and this week, I will change it to point to the current workbook.
I close the error dialog and right-click on the Monthly Sales query, so that I may Edit:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image5-1656934394.png/f6984742529e5eb329a84efcaee2d9a0.jpg)
This takes me to the Power Query editor, where I select the first step (Source).
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image6-1656934421.png/40baef84d3d3a43a26ad9a6e55cc2d27.jpg)
The M code for this step is:
= Excel.Workbook(File.Contents("C:\Users\kathr\OneDrive\Documents\SUMPRODUCT\PQ Blog\PQ blog 279 and 280 Sheets Ahead.xlsm"), null, true)
Instead of pointing at an external workbook, I need to change this to use the current workbook.
I can use Intellisense to help me here. If I delete ‘Excel.Workbook’ and start typing, I can see the following available functions:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image7-1656934596.png/d0a13b8ffa84adec180726a398b61ae7.jpg)
Therefore, instead of Excel.Workbook(), I can use Excel.CurrentWorkbook().
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image8-1656934632.png/f32957d0472ee532701779011deeb907.jpg)
Since I have a location, I don’t need the parameters, so I may delete them. Note that the Expression.Error dialog tells me that no arguments are required.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image9-1656934660.png/6e5a68d048bc4d644455454b94e7b0ea.jpg)
Here, I have the current issue with accessing data from within the workbook: I can see the tables (and Named Ranges) but not data on the sheets.
Next time, I will adapt the query and the data to get the results I need.
Come back next time for more ways to use Power Query!