Power Query: Top Tied
2 October 2019
Welcome to our Power Query blog. Today, I look at how to rank tied places.
The figures have come in for my imaginary salespeople:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
Since the top salesperson gets a bonus, I want to indicate clearly who is top. This principle can be expanded to include as many places as I like. I pull my data into Power Query using ‘From Table’ from the ‘Get & Transform’ section of the ‘Data’ tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
I sort my data by July Sales using the arrow next to the column name. I then choose to add an index column from the ‘Add Column’ tab (starting at zero).
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I can now create a custom column, which will allocate the top place if Index is 0.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
I click OK, and I can see the top salesperson, Mary.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
I ‘Close & Load’ this to Excel from the ‘Home’ tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
However, I have some late results, so I need to go back to my source data.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
Kevin’s results have been added, so I check the results of my query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
Well that doesn’t seem fair: Kevin has not reached the bonus category. I need to amend my query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
Since the index is incremented for each salesperson, Kevin is not getting the correct ranking. I need to group by July Sales. I can do this using ‘Group By’ on the ‘Transform’ tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I also add a new index column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
I can now add a new conditional column which will indicate top ranking.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image12.png/a1537847463e660a31158c8032525438.jpg)
I need to link this back to my salespeople. I will link this table to the table I had at step ‘Added Conditional Column’, before I grouped my data. If I look at the ‘Home’ tab, I have the option to ‘Merge Queries’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image13.png/917da985be13220165c8d2823e95344f.jpg)
Since I only have one query, I have to link it to itself, but I can amend the M code later.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image14.png/8c3be7af9f73d031acae69ed85a2e148.jpg)
I link on July Sales, since that will eventually give me all the salespeople.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image15.png/e63c0a4c21afc9afb438aacc09a59317.jpg)
I have generated the following M code:
= Table.NestedJoin(#"Added Conditional Column1", {"July Sales"}, #"Added Conditional Column1", {"July Sales"}, "Added Conditional Column1", JoinKind.LeftOuter)
This joins the query to itself at the same point, but I will amend it to link back to the earlier step.
= Table.NestedJoin(#"Added Conditional Column1", {"July Sales"}, #"Added Conditional Column", {"July Sales"}, "Merged Queries", JoinKind.LeftOuter)
Thanks to the similar step names, I only have to change the second “Added Conditional Column1” to “Added Conditional Column”. I call my new column Merged Queries.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image16.png/d082e3477129350b8a2a589156028e63.jpg)
I can expand my new column to get all the rows back, and I will choose to retrieve only the name of the salesperson from Merged Queries.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image17.png/a468c9c28195e8f18fdedfa59a0cf042.jpg)
I can now see that Mary and Kevin are both Top, and they will get their bonus! I remove Index and Count and reorganise my data before I ‘Close & Load’ to Excel.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image18.png/61935f470d8b9f21b7b7683ffca40895.jpg)
To check the query for more data, I enter the details for more salespeople.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image19.png/06909e3fbfc8faf87de7555c0b99e9d3.jpg)
When I refresh my query, the results are clear.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/148/image20.png/173ef895b62ce391674d271b99c4d178.jpg)
I clearly have lots of top salespeople due for a bonus!
Come back next time for more ways to use Power Query!