# Query Active Worksheet – Excel Power Query Tips

Let’s say we just got handed a report in Excel and have been asked to calculate various things from it. And the report looks something like the image below. Now, there are two ways to go about it:

1. Use VLOOKUP, INDEX, MATCH and IF statements to calculate all the statistics we need.
2. Convert the sheet into a big, ugly wall of data (as a Table) and ease our pain.

As data analysts, we are very comfortable with the first method, so much so that it appears boring and a waste of time. The second method, however, looks like something we’d be very interested in, especially if it automates this process for us. And our very own Oz du Soleil is here to show us this trick of the trade.

## 1 – The Requirements

There are a few properties our scattered report data should have:

• Labels at the top, and
• Consistency in layout of each subsection.

With a few tries on this method, any of us would be able to see that this consistency requirement is actually not as strict as it appears.

1. For Excel 2013, go to POWER QUERY tab, and select ‘From File’ under the Get External Data section. Now select ‘From Excel’.
For Excel 2016, go to DATA tab, and select ‘New Query’ under the Get & Transform section. Now select ‘From File’ and then ‘From Workbook’.
2. Now locate the active Workbook on the hard drive and press OK.
3. Select the sheet which has the report data and press ‘Edit’. The sheet will open up in the Query Editor. The image on the right shows how the data.

## 3 – Formatting

This is actually a fun part. We need to manipulate the data Power Query has grabbed to make it look like a table we would want to work with. Here’s what we’ll do with the data:

1. Right-click on the “State” header and select ‘Fill’ and then ‘Down’. This is shown in the image on the right. As we may have imagined, it fills the state names downwards wherever it finds “(null)”.
2. Now left-click on the filter on “State”,select ‘Text Filters’ and then ‘Does Not Contain…’. Type “Total” and press OK.
3. Now, filter out “(null)” from the “Rep” column.

## 4 – Let’s Load the Awesomeness

Once the cleaning has been done, all we need to do is press ‘Close & Load’ on the upper-left side of the Query Editor. And there we have it, the big, ugly wall of data we all are familiar with.

There’s another thing that needs to be highlighted. This wall is “dynamic”! What do we mean by that? Well, we wouldn’t want to do all of this again if new data is added to the report sheet. Especially when there are many formatting steps, not just three as in our example.

But there is no need to worry. When you would paste new data, click on any cell in this table just refresh it. Excel will automatically pick the new data up with the desired formatting! Check out the result in the image below.

## What’s next?

Give it a shot! See if this eases up your life. And your experiences with us below.

Tags

August 6, 2019

## How to Create a Relative File Path in Power Query

How to Create a Relative File Path in Power Query

June 21, 2012

## Interactive Periodic Table of Elements in Excel

Interactive Periodic Table of Elements in Excel

December 5, 2014

## A method for quickly importing and working with CSV files (part 2)

A method for quickly importing and working with CSV files (part 2)

April 27, 2015

## Excel Tables – What name did they used to go by? – Excel Challenge

Excel Tables – What name did they used to go by? – Excel Challenge

December 8, 2015

## 39: Power Query Book Author Ken Puls

39: Power Query Book Author Ken Puls

January 14, 2016

## How To Make A Calendar Table With Power Query – Excel Tips

How To Make A Calendar Table With Power Query – Excel Tips