Data Analytics & Visualizations — Replicating the Tableau Example In Excel — Part 2

Transforming The Dataset With Power Query

Don Tomoff
Let’s Excel
6 min readAug 13, 2018

--

In Part 1, the Extraction of 1.6 million records of data from the web into the Excel Data Model was explained. Yes, 1.6 million records.

In Part 2, we are going to focus our efforts on TRANSFORMING the data — using Excel’s Power Query tool — into information that we can analyze and use to develop the visualizations we want.

Transforming The Data

1 — Remove Extraneous Fields from the Dataset

  • Select just the columns I want to keep.
Power Query Editor — Select Columns I want to Keep
  • Click on the “Remove Columns >> Remove Other Columns”.
Remove Columns Not Selected
  • What’s left is a table of data containing just the fields I want to keep.
Dataset with Just Fields Needed

2 — Eliminate Records (Rows) That Contain “Bad” Data

Per the original article:

“In Tableau, filters can eliminate unnecessary, incomplete, or erroneous records, or restrict the data used in the analysis to records meeting certain specified criteria. In this example, two filters are added: one using the OUTNCCS field and the other using the RULEDATE field.”

Same applies to Power Query in Excel. So let’s perform the same steps as demonstrated in the article.

OUTNCCS Field

“ In this example, there are 3,142 records that are considered out of scope because the entity either is not a 501(c)(3) or is a foreign entity, or for some other reason.”

Here is the filter in Power Query, unchecking records shown as “OUT”:

Filter Out bad data in OUTNCCS Field

RULEDATE Field

“… and the earliest ruling letter date is zero, which suggests that the ruling date is missing or incorrect for these records.”

Here is the filter in Power Query, unchecking any records with a RULEDATE of 0:

Filter out all records with a RULEDATE of zero

Verify Final Record Count

“ Filtering out values of zero changes the minimum ruling date to 190001 (i.e., January 1900), and the remaining number of records in the data set is now 1,566,248.

Here is the view of final filtered record count in Power Query:

Filtered Record Count is Verified — Good to Go!

3 — Data Joining

Per the original article:

“ When analyzing data, it is frequently necessary or desirable to join two or more data sets. This is difficult to efficiently or easily do when using spreadsheets, but in Tableau it is relatively easy. For example, the sample data set includes a field labeled “NTEE1,” which is a code applied to each record that classifies the charitable entity according to one of the 26 groups representing charitable industries. It does not, however, include a field that provides the name of the industry associated with the code. Producing that information requires joining the original data file to another table that contains the code and names. The authors created an Excel file for this purpose, available with the online version of this article.”

Joining data sets is easy to do using the Data Model in Excel and establishing relationships.

Here is what I did:

Create Data Table with NTEE Code and NTEE Description

The authors in the original article created a separate Excel file for this purpose. This is not necessary.

Fortunately, the NCCS provides a link to a full list of NTEE Codes, which I could query, modify and import a data table into my data model.

List of NTEE codes to use for Power Query Import
Final Data Table — Query with NTEE Code and NTEE Description

Connect the Data Tables (Merge Queries Approach)

To connect the two data tables, I am going to use the Power Query “Merge Queries” approach to accomplish what a VLOOKUP function would do in Excel. (1)

(1) This data connection could also be accomplished by creating a relationship between the two table in the Data model — I will demonstrate that process in a future post.

  • Convert Queries to “Connection Only” — this removes them from the Data Model (we will load to the Data Model once we have created the Merged Query)
Convert Query Load to Connection Only
Uncheck “Add this to the Data Model”
  • Now, we will Merge the queries to add the NTEE Description to the import table (replicates a VLOOKUP in Excel). Open the first query in Edit mode.
Select data import query — “Combine >> Merge Queries”
In Power Query Merge Dialog box, select the Matching Columns & Click OK
  • Select the Expand icon and select just the NTEEDescription field to add to table
Select the Expand icon and select just the NTEEDescription field to add to table
NTEEDescription field added to Import Table; Select “Close and Load”
  • Then, we want to load the revised Import Table (fNCCSImport) to the data model. Right-click the Query, select “Load To” and check the “Add this data to the Data Model”.
Import Query Loaded to Data Model — Ready for Analysis
  • The data table is now ready for initial analysis!

4 — Data Pivoting (Analysis ready…)

Per the original article:

“ When using a spreadsheet to analyze data, users will often develop pivot tables to summarize and report information derived from the more detailed underlying data. While useful, Excel’s pivot tables are limited in several ways that Tableau is not.”

The authors are correct — we will use pivot tables to develop analysis — but they are incorrect in the limitations they list, which you will see below.

Let’s Create the First Analysis

Open Power Pivot >> Manage Data Model.

Select the Pivot Table Option — notice the numerous analysis options available!

In this case, I am going to create a basic pivot table — using the “fNCCSImport” data table previously added to the Data Model.

Power Pivot >> Manage Data Model >> PivotTable

Here is a basic Pivot Table showing the NTEE Description and the Count of each type of organization.

Basic Pivot Table — NTEE Description and Organization Count by Type

At this point, our data has been shaped consistent with the original article — but I’m not done yet.

In the next post — Part 3 — I am going to continue to revise our data set to provide additional analysis flexibility…then we will dive into the analysis of the data!

About Don

“It’s time for DIFFERENT”

Don is passionate about helping professionals and organizations keep up, develop and adapt to the changing business world that we operate in.

“What Do You Do?”

Connect with Don!

LinkedIn, Flipboard, Twitter, Snapchat

--

--

Don Tomoff
Let’s Excel

It’s time for DIFFERENT— On a mission to challenge the status quo to a more productive and effective end… #digital #Excel #data #analytics #genai #chatgpt