Include Excel files in query based on NamedRanges

o0omaxrbi

New Member
Joined
Oct 27, 2022
Messages
3
Platform
  1. Windows
Hello,

I have a folder with my Excel Files. In each of those Excel files, there is a Named Range called "MyRange". I only want to load those Excel Files, where the value of the named Range "MyRange" is TRUE. How do I do that in PowerQuery?

I somehow tried to get to the Named Data with adding a custom column in Powerquery which should do the following: Excel.CurrentWorkbook(){[Name="Ablaufdatum"]}[Content]. But it does not work. Can somebody help me?


1666883877523.png


Thanks
Max
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Power Query can do that. From the Data tab, select Get Data -> From File -> From Folder and select the folder with the files needed. That will result in a list of all the files like this:
1669384333885.png

Clicking the [Transform Data] button will bring you into the Power Query Editor with a list of files like this:
1669382345200.png

If you have unwanted files, filter them here. I suggest using Transform -> lowercase on the Extension column, and filtering it for only .xlsx extensions to prevent proceeding with any unwanted files. If the file names have a pattern, filter the Name column for just those files. It works just like a Table.

Now at the Top Right corner of the Content column click on the double down arrows at the top right corner of the column
1669382933889.png

and you'll be presented with view of one of the files which will be the Sample File. If all of your files have a range named MyRange, you'll see this:
1669383054023.png

Select MyRange and Power Query will pull in that range from all the files in the folder and append their data into one Output query with the same name as the folder:
1669383496138.png

Files that do not have that named range will not be brought in. You'll notice that the first row was not promoted to header. Do not change it in the final output query. Instead select the Transform Sample File query and promote the first row there. Also rename any columns there. NOTE: any files with a different structure - different column names, more columns etc. will result in something you may not want or break the query preventing any output.

There are plenty of Playlists on YouTube on Power Query like the ones from Mr. Excel and Mike at ExcelIsFun which includes before and after sample files. Power Query is a relatively easy skill and once learned will save you hours of work!

Good luck.
 

Attachments

  • 1669382227956.png
    1669382227956.png
    57.3 KB · Views: 10
Upvote 0
Solution
Hello,

I have a folder with my Excel Files. In each of those Excel files, there is a Named Range called "MyRange". I only want to load those Excel Files, where the value of the named Range "MyRange" is TRUE. How do I do that in PowerQuery?

I somehow tried to get to the Named Data with adding a custom column in Powerquery which should do the following: Excel.CurrentWorkbook(){[Name="Ablaufdatum"]}[Content]. But it does not work. Can somebody help me?


View attachment 77188

Thanks
Max
Max,

Thanks for the checkmark! One thing I should have mentioned is that the Query labeled Transform Sample File is basically the template for what happens to files pulled in. Changes like a sort or final touches can be made on the final Query (Junk), but if you find something that can be done to all the files, it's best to do it to the Sample File Transformation.
 
Upvote 0

Forum statistics

Threads
1,223,406
Messages
6,171,927
Members
452,434
Latest member
NUC_N_FUTS2

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