Power Query: Month Mayhem – Part 5
31 July 2024
Welcome to our Power Query blog. Today, I create mapping queries which I will be using to move the data.
My salespeople are back from their break and I have more reports to construct. I have a report with a list of the clients they have been working with each month:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image1-1722331299.png/742c5ee16ed4279bfafb9a89a2421cab.jpg)
I would like to display the amount details in the salesperson sections, but have it aligned to the relevant month at the top of the page:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image2-1722331316.png/ad77aca455eab16bbccdcbb7f0354791.jpg)
Last time, I created the queries I need for the amount data. As a reminder, I first created the Amounts query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image3-1722331394.png/3aaa62974942da139ea6b3688f73f0c1.jpg)
then I took a reference copy of Amounts, to create Amounts_Unpivoted:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image4-1722331411.png/910a49c05425093465032f8e7fba6afd.jpg)
This time, I will consider how I am going to move the data by creating mapping queries.
I am going to merge the amount and month data. I start in the Amounts_Unpivoted query, and I choose to ‘Merge Queries as New’ from the ‘Merges Queries’ dropdown on the Home tab:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image5-1722331434.png/d6104db42f4f0a05859d3c266e83d1e7.jpg)
In the dialog, I choose to merge with the Months_Unpivoted query:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image6-1722331454.png/87b50a359011a838142f13ce0482bd54.jpg)
This will only pick up the month data from the Amounts_Unpivoted rows. I click OK and rename the new query ‘Column_Mapping’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image7-1722331475.png/fa2b97cc78edb2b2ae4edd3f8d84c29e.jpg)
I use the expand icon next to the Months_Unpivoted column header to choose which data to extract:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image8-1722331493.png/d750f90a9cf0c1ddb63320e96469abb5.jpg)
Since I am looking at what columns to map to, I need the Attribute column. I already have a column with this name, so I choose to ‘Use original column name as prefix’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image9-1722331517.png/abe3e51856185ca56ab3f59369638576.jpg)
I can see that sometimes the column mapping appears in Attribute, and when it doesn’t, it appears in Months_Unpivoted.Attribute. I need to create a ‘Conditional Column’ from the ‘Add Column’ tab that will either use the value in Months_Unpivoted.Attribute, or if that is null, it will use Attribute:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image10-1722331551.png/036feac90f2144876e25c0fafa09f485.jpg)
I have called the new column Mapping.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/./image11-1722331571.png/239887d501e3b7a281ac1661428c9a72.jpg)
Next time, I will continue mapping my data.
Come back next time for more ways to use Power Query!