Forum Discussion

S_loke's avatar
S_loke
Advocate I
6 years ago
Solved

Power Query lookup against a filtered table

Hi,   Currently i have the requirement to build out a table which requires a conditional lookup to return a max value BUT only if the value fits a specific condition.   2 tables with the same str...
  • dax's avatar
    dax
    6 years ago

    Hi S_loke

    You could try to refer to below M code(in addition, I think your date in Table 2019/1/5  is 2019-May-1 instead of 2019-jan-5)

    let
        Source = Table.NestedJoin(TableA, {"Obj"}, TableB, {"Obj"}, "TableB", JoinKind.FullOuter),
        #"Expanded TableB" = Table.ExpandTableColumn(Source, "TableB", {"Transaction Date"}, {"TableB.Transaction Date"}),
        #"Added Conditional Column" = Table.AddColumn(#"Expanded TableB", "Custom", each if [Transaction Date] >= [TableB.Transaction Date] then [TableB.Transaction Date] else null),
        #"Grouped Rows" = Table.Group(#"Added Conditional Column", {"Obj", "Transaction Date"}, {{"max", each List.Max([Custom]), type date}})
    in
        #"Grouped Rows"

    Best Regards,
    Zoe Zhi

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.