Power Query: Heading Off – Part 6
20 March 2024
Welcome to our Power Query blog. Today, I look at how to solve an issue that occurs when I load to a Table with no headers.
I plan to show a particular issue with Power Query and Tables without headers. However, first I need to create the scenario, and I will show a few methods and tips along the way. I have two Tables of data:
- contains my salespeople’s expenses (Expenses)
- determines the expenses that will be covered by each supplier (Supplier_Limit).
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image1-1707934940.png/ef269a5646089e1768b92c98624ba127.jpg)
In Part 1, I created two [2] queries, and grouped Expenses.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image2-1707934970.png/b33577bd2e64f672cfc7027595c5b984.jpg)
In Part 2, I merged Expenses with the Supplier_Limit query to create Limit_Exceeded, which tells me if any limits have been breached.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image3-1707934992.png/22b34ed6353c424e702ca5312642e9a8.jpg)
In Part 3, I loaded Limit_Exceeded to a new worksheet.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image4-1707935598.png/38d61042abde2ad560d8d96729ec3f16.jpg)
I removed the header row and changed some of the data in Expenses.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image5-1707935617.png/1dc4f4e0b0451373dc0e81129c277761.jpg)
In Part 4, I ran the query for a single salesperson.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image6-1707935650.png/ee3604fc3a88f1f1542e568e3960445a.jpg)
I extracted this cell and created a parameter P_Salesperson:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image7-1707935683.png/478d745575ee5a607eefb7a520fd8969.jpg)
I used this parameter to limit the data in Expenses:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image8-1707935705.png/e319f0db2b88b11906de4744e451f26e.jpg)
When I refreshed Limit_Exceeded, I checked the results:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image9-1707935730.png/709c92cdc01897fa9ba8178b328ee768.jpg)
The results correctly showed one row of data and no headings. However, things changed last time when I selected a different Salesperson:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image10-1707935768.png/52d50e717ba4d75e76b958b4d01a3b1e.jpg)
When I refreshed Limit_Exceeded, it had moved the data from the previous selection into the header row.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image11-1707935794.png/b59051799512c07c01217538cf7f03b7.jpg)
When I deleted the top row from the Excel sheet, things got worse!
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image12-1707935812.png/32d089bb8ae61bc3f5faa17a5e8b76b3.jpg)
Since the problem is being caused by writing an empty query to a Table with no headers, I need to change what happens if there is no data returned by Limit_Exceeded.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image13-1707935838.png/d6d790b22c80bf1ec0a10c6fb9cd22be.jpg)
I could add a row if my table is empty. One way to do this, it to create a helper query that I can append to my existing query. I don’t need to include all the columns; one will be enough. I create a new blank query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image14-1707935869.png/c20adfc82ac49ceac7ec593f7f61eccd.jpg)
This is going to be a very simple query!
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image15-1707935885.png/bc27e171c02c46f995dcc918c45ac344.jpg)
I have created a list of one blank row by using the M code:
= {“ ”}
I need to convert the list to a table so that I may append it. I use the ‘To Table’ option on the ‘List Tools’ Transform tab:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image16-1707935952.png/b9a4f0102c882aa31836b5dd2c57f067.jpg)
I take the defaults and create the table:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image17-1707935973.png/51d0f6a9814d94160a68c73b60516b21.jpg)
I go back to Limit_Exceeded, and choose to ‘Append Queries’ from the Home tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image18-1707936002.png/00b82a923d97be3a9886f83e9b6cd644.jpg)
I select NoRows, and click OK:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image19-1707936028.png/e54a63e5d9cb20a3d3c4b1659ef2f275.jpg)
I delete Column1, and ‘Close & Load To…’ from the Home tab (as I do not want to load NoRows to the workbook). Having set NoRows to ‘Connection Only’, I view the results:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image20-1707936050.png/8dcdf60619b2ea7f46aab696c7cdebdf.jpg)
This is looking much better! Clearly, it’s not ideal to have a blank row, but it is better than showing the wrong data. I’ll refine this approach next time so that I don’t add a blank row if I have data.
Come back next time for more ways to use Power Query!