The Query and the Pivot – When your Tables need more than a Sheet
Here we are again with our sketchpad, wondering what to draw as we sip our Cognac. Last week, we spoke on basic formulaic maneuvering within a simple spreadsheet interface. Things like sumifs, xlookups, uniques, pivot tables, even goal seek – the basic drill-set for any office Ken or Karen putting together some tabular insights. But what about when our need for scale and speed stretches beyond our sheets?
Before we go full enterprise database mode with the likes of SQL, and stretch beyond that into data warehousing, we have a few user-friendly intermediaries that we can call upon right within that cozy spreadsheet framework we know so well. Meet your ultimate tabular performance enhancers – Excel Power Query and Power Pivot. These tools enable you to execute complex data transformations, build data models, and perform advanced, multi-step analyses without extensive programming knowledge – really without any at all.
In this article we will get oriented with Power Query and Power Pivot, more or less within the context of basic numerical reporting. Two videos are linked below – one for Power Query and one for Power Pivot, where I walk you through how to get into the interfaces and start working some magic. After the accompanying verbiage, I will close the article with a very brief functional comparison with SQL and Python (specifically the use of Pandas, NumPy, and Matplotlib within the Python framework). Remember, although the process can feel tedious or overwhelming as you ramp into it, if you focus on getting a little progress – however small – everyday, you will surprise yourself with how much you can learn in just a few months.
Power Query: If a janitor and a bounty hunter made a user-friendly analytics tool
In case you haven’t heard of it, Power Query is an Excel add-in that allows you to connect, combine, and refine data from a variety of sources, such as the web, folders in your network or on your desktop, or even tables within the file you have open. It provides an intuitive interface within which you can perform your data transformations, making it easier for users who might not be familiar with advanced programming languages (Chen, Yan, & Wu, 2020). That’s really the key value here – the short learning curve and nearly immediate accessibility to anyone even vaguely familiar with spreadheads. When I need to clean up a file or a would-be table in Excel, I invariably do so with Power Query.
How to Use It
Here’s the video to get started, but below I have provided some of the key steps and concepts: Power Query Intro
1. Data Hunting - Loading your Data:
Once you’re in Excel, navigate to the “Data” ribbon at the top of your screen. Click “Data” and then move your cursor toward the top left and click on … wait for it… “Get Data” (Microsoft, n.d.), to load data from various sources, such as your favourite Excel files, your org’s sensitive network folders, government websites, family friendly web pages, etc.
2. Data Cleaning - Transforming your Data:
Once the data is loaded, Power Query Editor opens and gives you several different tools and features that you can use to clean and transform your data. Not only can you filter and remove rows, expunge duplicates, pivot and unpivot your data, merge and append tables, etc., but you can perform complex calculations just like the ones you would use in a regular spreadsheet (Chen et al., 2020). This can be done by adding custom or conditional columns. In the coming weeks, I will add a bunch more walk throughs detailing the many steps you can perform, depending on your needs and what you want to automate.
3. Data Memory - Creating your Queries:
Power Query records each transformation step as a query – kind of like a macro, which we will get into in the coming weeks. That’s the beauty of PQ – it allows you to essentially program a set of steps and then rerun them effortlessly, with the click of the refresh button, every time your dataset is updated. These queries can be edited, combined, and reused for other datasets, saving you, quite possibly, hours of manual work every week (Reza Rad, 2019).
4. Loading Data into Excel:
After your transformations are complete, you can load the cleaned data back into Excel, either as a table, a pivot table or directly into Power Pivot for further analysis. As you will see with Power Pivot below, this allows you to layer in a multitude of calculations without altering the raw dataset that you’ve queried in.
Use Cases for Power Query
Power Pivot: If a detective and a chess master made a user-friendly analytics tool
Power Pivot extends Excel’s capabilities by allowing users to create complex data models using large datasets. It integrates closely with Power Query, as mentioned above, enabling users to readily analyze and visualize their cleaned data through pivot tables and pivot charts (Reza Rad, 2019). Importantly, it uses the same analytical language as Power BI (Data Analysis Expressions (DAX)), and so if you understand Power Query and Power Pivot, you are ready for BI. I actually learned Power BI first, believe it or not - the only reason I went and learned Power Pivot was because of its general familiarity amongst my team mates, relative to BI (BI videos and walk throughs will be coming very soon).
Here is the Power Pivot intro video I recommend for anyone with an extra large glass of Cognac: Power Pivot Intro
How to Use Power Pivot
After loading and transforming data using Power Query, you can add it to the Power Pivot data model. First, navigate to the “Power Pivot” tab and select “Manage” to open the Power Pivot window (Microsoft, n.d.).
Recommended by LinkedIn
2. The Match-Maker - Establishing Relationships:
Within the Power Pivot window, you can form relationships between different tables, similar to a relational database. This allows you to analyze data across multiple tables (Chen et al., 2020).
3. The Calculator - Creating Measures and Calculated Columns:
Power Pivot enables the creation of calculated columns and measures using Data Analysis Expressions (DAX), as mentioned above. This adds powerful analytical capabilities to your data model (Reza Rad, 2019).
4. The Kaleidoscope - Visualizing Data:
Once the data model is complete and your calculations are applied, you can create pivot tables and charts within Excel, using these relationships and calculations established in Power Pivot (Microsoft, n.d.).
Use Cases for Power Pivot
Comparing Power Query and Power Pivot to SQL and Python - don't blink
SQL
SQL (Structured Query Language) is a standard language used for querying and managing databases. Power Query can be seen as a visual interface for performing SQL-like operations, such as filtering, joining, and aggregating data. However, SQL is much more powerful for managing large-scale databases and offers much more control over data queries (Zou & Zhang, 2022).
In sum:
Python (Pandas, NumPy, Matplotlib)
Python, with libraries like Pandas, NumPy, and Matplotlib, offers a programming-based approach to data analysis. Pandas is used for data manipulation and data framing, NumPy for numerical operations, and Matplotlib for visualizing data (i.e.. charts, graphs, etc.). Compared to Power Query and Power Pivot, Python offers much greater flexibility and scalability for complex and custom data analysis tasks (McKinney, 2017).
In sum:
In Sum(x)
Power Query and Power Pivot are invaluable tools for anyone looking to perform advanced data analysis within Excel. You like your sheets, your team only knows sheets, and in the time it would take you to set up your MySQL or Pycharm interfaces for the first time, you could have your full monthly reporting dashboard built and submitted to your team for review in Excel. These Tabular heavyweights provide powerful capabilities while maintaining user-friendliness, making them accessible to a wide range of users. While SQL and Python offer more power, flexibility, and scalability, Power Query and Power Pivot... well, they are like the mom's-home-cooking version of analytics. Familiar, cozy, and, to a point, still get the job done.
Bis zum nächsten Mal, dear reader.
References
Lead Software Engineer at aptitude LLC
8moStill have to double take when I see your posts. Your writing style is similar enough to my own that I have to scratch my head and go, "I didn't remember posting anything like that..."