Microsoft Excel: Create a State / Region Lookup Table in 5 Minutes with Power Query
Just Grab Online Link and Shape The Table
If you would like to download the Excel file I refer to below — you can get it here.
Introduction
A common “reference” table needed when you are working with data is a STATEs of the USA related lookup table.
The simplest form of this is to group the states into the four regions of the country — Northeast, South, Midwest, and West.
With easy access to this data table, I have the ability to quickly group any data I work with that is broken down into states into a “higher level” region analysis (or Total Data into a more granular Region level view).
I will explain how to do this using the common data analytics approach of “ELTR” — Extract, Transform, Load, Report.
How It’s Done
Extract Data (Find Source and Import Data) — 1:00 Minute
In this case, I do a Google search and select a data set that can be easily converted to the format I want. There are tons of resources — find and pick one you are comfortable with.
This is an Excel file that the US Census Bureau hosts. I’m simply going to get the URL of this file and use it in Power Query.
The “Source” file looks like this:
We want to query data from “the web”. Paste the URL link and click OK. Review the Table Names and select the table you want to import.
In Excel, the initial Power Query “edit” screen view is here.
Transform (Shape the Data Table to our Needs) — 3:00 Minutes
- Modify the field types and move the name column to the first column.
- Add a “Custom” column to assign the Region Name to each row. Then use the “Fill” command to populate EVERY row of the data set.
- To create the column, we use the “Conditional Column” function…
- Then, using the “State (FIPS)” column, filter out the “0” values. These are not STATE related records, so I am removing them from the final lookup table.
- Now, the table shows just States and Regions records.
Just a couple more steps to finalize my table —
- Sort alphabetically by State,
- Remove the # reference columns — not needed anymore.
Here is the final table (for now).
Load (Bring Table Into Excel for Use as a Lookup Table) — 1:00 Minute
At this point, I can load the Table into an Excel worksheet OR load it into the “Data Model” (in the background of Excel workbook).
Load into Data Model
Load as Table Into Excel
There you go — 5 minutes from Idea to Finished Table. Power Query makes it that simple!