Power Query (files from folder). Change source (path) based on a cell value in Current WorkBook

Want2BExcel

Board Regular
Joined
Nov 24, 2021
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
So I found this video about the use of named ranges to make a Power Query dynamic file path and I thought this looks like a great idea. Easy to make a macro to a button in the worksheet, guiding users to point at their personal folder, where ever they want that. Thereby creating a folder path in a cell that Power Query then can use as reference to update the path for it's datasource. In this case the datasource (user's folder) holds the .csv files need to make the entire workbook perform as it was intended to begin with. The folder gets loaded with more and more files as times go by and even though the user probably don't change this when first set, the problem lye in every user needs to do this once so that Power Query knows where to look for the .csv files. This can be a bit complicated to explain to a user, without them going 🤯

Forgive me if I don't use the right terms. I'm really new to power query and all it's beauty.
So even though this video (and everything else on this matter I've read) is about showing a path to a file, I thought that it could be used to my task, show a path to the folder (that holds the files). In a standard query>from file>from folder, I don't need to give file names. I just point to the folder, set up the query and every time i put in a new csv file, it automatically reads the new file. So I figured, hey, just point to the folder with this new approach an all the files is then also found...but I think there is something I don't take in consideration. Something is behaving strangely :unsure:

In the advanced editor I've changed this according to instructions:
Power Query:
Source = Folder.Files("C:\Users\Want2BeExcel\Documents\TEST\DATA"),
to this (GetFolder is the named range cell that gets the folder path from the users button-click)
Power Query:
FilePath = Excel.CurrentWorkbook(){[Name="GetFolder"]}[Content]{0}[Column1],
Source = Folder.Files(FilePath),

And well it kind of works.... When I set it up it works perfectly. But when performing a test run I noticed it wasn't working at all.
As mentioned, I use GetFolder as my named range. When the content of GetFolder changes value (a new folder path) , Power Query don't register it....not even if I update all. The DataSource don't update to the new value at all...weirdest part is, if I open advanced editor and just briefly change GetFolder to Getfolder2 in FilePath = Excel.CurrentWorkbook(){[Name="[B]GetFolder[/B]"]}[Content]{0}[Column1] I, of course get an error at first, but THEN when I the change it back to GetFolder, the new value is now registered. What, Why Pfft!? 🤬 Why can't it just do that initiarially...it's the same line! I really don't understand. It's like the Query can't update it's data source value automatic. It can "read" GetFolder just fine or else I would get an error, so why the h... don't it update automatically 😬 It kind of ruins the whole purpose of doing this if it doesn't help the user. It's really not a bonus if I have to explain to users, that they just have do open this and this and enter advance editor and just change the Name="GetFolder" briefly and then back. It's REALLY annoying!!!! Can anybody pleeeeease explain this for me?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I FINALLY figured it out! The problem wasn't the code. The problem was that the main query, the one all the others rely on, was "loaded into data model". I unticked the box and holy moly, the SOB purred like a little kitten 🐱🥰 Oh the joy...the satisfaction of solving a very annoying problem 🥳😎
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top