Forum Discussion

APEREZ2's avatar
APEREZ2
Advocate I
4 years ago
Solved

How to define if date is in a range

Hi,

I have the following problem. I need to relate the table of prices:

StartingPriceEndPriceProductUnit Price
2021-03-012021-05-22Apple Tree1.24
2021-05-232021-07-31Apple Tree1.54
2021-08-012022-04-01Apple Tree1.80
2021-03-012021-05-22Bonsai 2
2021-05-232021-07-31Bonsai 1.86
2021-08-012022-04-01Bonsai 1.79

With the sales tables, that contains an structure like this:

ProductQuantitySales Date
Apple Tree1232021-03-22
Bonsai2342021-05-09
Apple Tree1002022-01-22

How can I relate the two tables to obtain the Unit Price of each order. Because on Excel for me it's clear that with EndPrice column and XLOOKUP could be work, but on Power Query no.

  • Use below formula in a custom column in second table. First table is PriceTbl.

    Table.SelectRows(PriceTbl, (x)=> x[StartingPrice]<=[Sales Date] and x[EndPrice]>=[Sales Date] and x[Product]=[Product]){0}[Unit Price]

      

1 Reply

  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    Most Valuable Professional

    Use below formula in a custom column in second table. First table is PriceTbl.

    Table.SelectRows(PriceTbl, (x)=> x[StartingPrice]<=[Sales Date] and x[EndPrice]>=[Sales Date] and x[Product]=[Product]){0}[Unit Price]