The comments of my last post collected a tip that I thought it was worth exploring on pulling Excel named ranges into Power Query.
I made the claim that Excel MUST have the data in an official Excel table. As LoganEatsWorld pointed out, that’s actually not true any more. If you’d like to give this a go, you can download this workbook to follow along.
What’s in the file?
The file is very basic. It simply contains one table, and one named range of data:
The table is highlighted in the blue table style, and bears the name “Stats”. The named range is surrounded by the black outline, and is called “Breeds”.
Connecting to Excel Data:
The reason I never found this is that my method was always to go to the Power Query tab and click –> From Table. That will work great to get the data out of a table, but it won’t work for the named range. So let’s try this a different way…
- Go to Power Query –> From Other Sources –> Blank Query
- Click in the formula bar and type the following:
(Yes, it’s case sensitive… I’m starting to reconcile myself to the fact that it’s Power Query so I’m just going to have to get over it.)
What ends up happening is a bit of magic:
Interesting… we have two tables listed! The first is our official table, the second is our named range. Cool!
Let’s click in the blank space to the right of the green “Table” text in the Breeds row:
The preview pops up and, sure enough, that’s our named range data:
Working With The Data
All right, let’s click the green Table text and break open that named range:
One notable difference here (in fact really the only one), is that Power Query doesn’t automatically recognize the header row. This is due to the fact that an Excel table actually has a named header row to promote, where a named range does not. No big deal though, as we can easily deal with that:
- Go to Transform –> Use First Row As Headers
At this point, we could save the table to the worksheet or data model, as we need.
So this is cool. It’s awesome that we can get to named ranges, as I have a LOT of workbooks that use these, and there are occasions where I don’t want to convert them to official Excel tables. Despite the fact that we can, however, you pretty much need a secret decoder ring to find it, and that’s not so good.
It would sure be nice if there was a more discoverable way to pull in a named range… but where?
Suggested Accessibility Option 1
When I look at Power Query’s “Get External Data” function, it seems logical to me that it should end up somewhere in that area. Looking at the group:
I kind of like the ability that comes with the “From Table” feature which works from the table you’re in (if you are), and lets you create a table if you’re not inside a table when you click that button. But I wonder if it would be better served as a SplitButton/menu/submenu structure that offered the following options:
- From Table
- Current Table
- Other Table
- List of other tables in the workbook
- Named Range
- List of named ranges in the workbook
- Create New Table
- Create New Named Range
Actually, there is another change I would make to that group, and that’s to move the “From Blank Query” out of the “From Other Sources”, and give it it’s own button. (I create a LOT of queries from scratch now, and it’s just extra clicks in my way to do so.)
Suggested Accessibility Option 2
I’m not sure this is so much of an alternate as something additional I’d like to see, actually. An “additional sources” button on the Home tab would be awesome. If that had the ability to pull up all the existing tables or named ranges in the workbook, and add them to the Power Query script as a “Source2=…”
I think the implications of this would be two fold:
- It would allow you to add a data source after creating a blank query, and/or
- It would allow you to add additional data sources into the same query.
The latter is certainly something I do semi frequently, as I don’t want to have multiple Power Queries created that are then merged together. I’ll add both sources manually in the same query then merge them.
At any rate, just some thoughts. If you have any on the subject please feel free to leave them in the comments. 🙂