Forum Discussion

peterpan's avatar
peterpan
Helper I
2 years ago
Solved

Fetching Data based on Start Date & End Date

I have two tables- Table A:     Table B:     I want to bring rates for companies as mentioned in Table A in Rates column of Table B. There could be multiple rates for a varied durat...
  • AlienSx's avatar
    AlienSx
    2 years ago

    peterpan null is reserved for Table.FillDown. So I used "none". You are free to replace it with anything else in the code but null. Or simply replace "none" with null after all transformations. 

    let
        tblB = your_table_B,
        tblA = Table.AddColumn(your_table_A, "Date", each [Start Date]),
        diff = Table.RemoveMatchingRows(tblB, Table.ToRecords(tblA), "Company"),
        missing = Table.FromRows(
            Table.ToList(diff, (x) => x & {"none"}),
            {"Company", "Start Date", "Rates"}
        ),
        combine = tblB & tblA & missing,
        sorted = Table.Sort(combine,{{"Company", Order.Ascending}, {"Date", Order.Ascending}, {"Rates", Order.Descending}}),
        f_down = Table.FillDown(sorted, {"Rates"}),
        filter = Table.SelectRows(f_down, each ([Start Date] = null)),
        z = Table.SelectColumns(filter, Table.ColumnNames(tblB) & {"Rates"})
    in
        z