How do I do an Outer Join using two critera, one of which is variable?

amail

New member
Joined
May 16, 2017
Messages
4
Reaction score
0
Points
0
Hello all.

I have the following two tables:

Employee Table
EMPRATEEFFDATE
Brandon$13.502/1/17
Sean$12.002/1/17
Brandon$14.504/1/17
Melanie$12.002/1/17
Melanie$13.003/1/17
Brandon$16.005/1/17
Job Table
JOBDATEEMPHOURS
00012/15/17Brandon3
00012/15/17Sean3
00022/25/17Sean2
00022/25/27Melanie3
00033/10/17Melanie6
00033/10/17Brandon4
00044/15/17Brandon3
00055/1/17Brandon6
00055/1/17Melanie5

I want a column on the Job Table that uses the correct rate for the employee and the date range. If I do a full outer join on EMP and DATE, I get three entries for every job with Brandon and two entries for every job with Melanie. I want just the single entry with the correct rate for the date.

Color me stumped.
 
Maybe it would be better to attach the spreadsheet so you can see what I'm up against. I mis-spoke in my first post. I'm not getting several values for each employee, just one, but it's still not what I need - Rate cannot be null, people need to be paid!
View attachment qryTest.xlsx
 
You can join on EMP only and then select the rate with the latest effdate <= job date, like in the following code:

Code:
let
    Source = Table.NestedJoin(qryJOBS,{"EMP"},qryEMP,{"EMP"},"NewColumn",JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(Source, "Rate", (This) => Table.Max(Table.SelectRows(This[NewColumn], each _[EFFDATE] <= This[DATE]),"EFFDATE")[RATE]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"NewColumn"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Rate", Currency.Type}})
in
    #"Changed Type"

Beware: if you adjust the #"Added Custom" step via the gear button at the right of the step name, than you'll get "each " in front of "(This) =>" and you need to remove that "each '.
 
Thanks so much - this has saved me a lot of grief! I guess I have to learn about (This).
 
I'm curious how you built that custom column. Would you mind stepping me thru the steps?
 
Back
Top