There are many scenarios where raw data itself isn’t enough to complete a task efficiently. For example, we may need to add manual information, such as categorization, commentary, or reference numbers.
In this post, we look at this process and understand how to add manual information to a query.
Download the example file: Click the button below to join the Insiders program and gain access to the example file used for this post.
File name: 0186 Add manual info to a query.zip
Watch the video
If we want to load data from a source using Power Query and add manual information, there must be a unique reference for each row in the Table.
Since the positions of rows may change, we need a unique reference to ensure the manual information is merged with the correct row of the data.
In many scenarios, the input will already include a unique reference. In this case, the process is reasonably straightforward.
Therefore, I wanted to work through an example where we need to create a unique reference as part of the process itself.
This is the example we are working through:
Since bank statements, in my experience, do not have unique reference numbers for each row, we must create the reference ourselves.
Here is a screenshot from one of the CSV files.
Note: In the example, the dates in the CSV files are UK dates (dd/mm/yyyy format). Even if your region uses an alternative date format, it should not prevent you from completing the example.
OK, let’s build out the solution.
The actions for Step 1 are covered extensively in other posts (combine files in a folder using Power Query), so we won’t go into tremendous detail here.
Let’s start by getting the data from the folder.
At this point, the Preview Window should look like this:
Using the Source.Name (i.e. the name of the file) and a row number from each CSV we can create a unique reference.
Select the Transform Sample File query.
From the ribbon, click Add Column > Index Column. This gives us a row number within each CSV file.
Select the query with all the files combined (Files in our example)
Select the Index column, then hold Ctrl and select the Source.Name column.
From the ribbon, click Transform > Merge Columns
In the Merge Columns dialog box, select a Separator (I’ve chosen colon) and provide a New Column Name (I’ve chosen Unique Ref). Click OK.
Now we can close and load the query as a Table in Excel by clicking Home > Close & Load (assuming you have the default setting applied).
Excel displays a Table with the bank transactions along with a Unique Ref column.
That completes Step #1.
Now let’s add the column for the manual information. In the example, I’m adding a commentary column.
In the cells to the right of the query Table add a new column header called Commentary and add a few lines of example text.
That’s it for Step #2.
We want to load the Table with the additional column into Power Query.
Select a cell in the Table and click Data > From Table/Range
To keep things clear. Let’s call this new query Manual Info
Next, we want to merge the Commentary column from the Manual Info query into the first query, using the Unique Ref we created earlier.
Select the first query, then from the Ribbon, click Home > Merge Queries.
In the Merge Queries dialog box enter the following:
A Manual Info column is added to the first query.
Expand the new Manual Info column, but include only the Commentary column.
We don’t need to load the Manual Info query into Excel. So, click Home > Close & Load (drop-down) > Close & Load To…
In the Import Data dialog box, select Only Create Connection, then click OK
The Table in Excel now show Commentary and Commentary2 columns.
Delete the Commentary2 column, this is the manual column we created earlier, which is no longer required.
We can now add more commentary, we can also add new files to the folder. When we click Data > Refresh All, the manual information stays with the correct data row.
Using this technique there are many things that might catch us out:
There are many other scenarios where this technique could be useful:
In this post, we have seen how to add manual information to our data using Power Query and Tables.
The key elements for success are:
Related Posts:
Discover how you can automate your work with our Excel courses and tools.
Excel Academy
The complete program for saving time by automating Excel.
Excel Automation Secrets
Discover the 7-step framework for automating Excel.
Office Scripts: Automate Excel Everywhere
Start using Office Scripts and Power Automate to automate Excel in new ways.