Power Query: Selective Staffing Part 7
8 December 2021
Welcome to our Power Query blog. This week I look at an example that considers values that can be marked as included or excluded.
Last week, I was looking at an example where I had a table of quote data for each of my salespeople, and a list of salespeople that I wished to view quote details for:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I used an Inner Join to merge the data to get the solution:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
This time, I will look at how I can expand this to allow me to consider inclusion and exclusion in the same example. To begin with, I will consider the following situation:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I begin in exactly the same way as last week, by extracting the tables to Power Query using ‘From Table/Range’ in the ‘Get & Transform’ section of the Data tab.
The quote data is in table Staff_Quotes_Join_E:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
The staff to be excluded are in table Quote_Selection_Join_E:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
I can exclude these values by performing a join. I do this from ‘Merge Queries from the Home tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
This time, I will use a Left Anti Join, which will show me the rows that are only in Staff_Quotes_Join_E and NOT in Quote_Selection_Join_E. I need to specify the columns to compare:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
This sounds exactly like what I need, so I click OK.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
I can delete the Quote_Selection_Join_E column to get the data I need:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
Now I will consider the situation where we have a list staff that are marked as included or excluded.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
This time, I am linking to a table that includes all the salespeople, and they have a flag next to their name. I extract the new data into a table called Quote_Selection_Both:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
I can still solve this with a merge, but I need an extra row in Staff_Quotes_Join_E:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image12.png/a1537847463e660a31158c8032525438.jpg)
This highly complicated column always has the value “I” and will simply allow me to merge with Quote_Selection_Both.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image13.png/917da985be13220165c8d2823e95344f.jpg)
I have used an Inner Join to keep the rows I need:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image14.png/8c3be7af9f73d031acae69ed85a2e148.jpg)
I can now delete Include and Quote_Selection_Both to get the data I need:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2021/power-query/262/image15.png/e63c0a4c21afc9afb438aacc09a59317.jpg)
Come back next time for more ways to use Power Query!