Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
LudivineLOU
Helper I
Helper I

Lookup between 2 days

Hello, 

I have a price table with different article and price validate for the period between "valid from" until "valid to"

 

Table price :

Article      valid from       valid to              price

   A         01.01.2020         31.12.2021          10

   A         01.01.2022         15.06.2022           12

   A         16.06.2022         31.12.2030           14

   B         01.03.2020         31.12.2021          100

   B         01.01.2022         15.08.2022           120

   B         16.08.2022         31.12.2030           160

 

I have a table order with my order qty

 

order date      order        article    price

02.04.2020        raw1            A           ?*

02.04.2020        raw1            B            ?**

17.08.2022        raw1            B            ?***

 

I need to find the price of the article based on the order date. 

In the table bellow, the price must be 10 (?*), 100(?**), 160(?***)

 

Could you please help me with a formula dax ?

Thank you,

Best regards. 

 

 

 

 

 

 

 

 

 

 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@LudivineLOU (1) LOOKUPVALUE Range - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

lbendlin
Super User
Super User

Does it need to be DAX?

 

Prices:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hY5RCoAgEESvEn6L7Kwl/tY1xLt5Fk/WalQWmTAsDOxjXggqpymntd4rSiuCkTAxScnJwoBLhVSQinpMciWxGHJN5T8W7vF8rtpDAvPNbp+7tmtMI/Sl7FvlX7g4+76zEzju", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Article = _t, #"valid from" = _t, #"valid to" = _t, price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Article", type text}, {"valid from", type date}, {"valid to", type date}, {"price", Currency.Type}},"de"),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Article", Text.Trim, type text}})
in
    #"Trimmed Text"

Orders:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDSMzDRMzIwMlDSUTq0QKEosdzw0AIIG4gcgexYHYLKnKDKDM31DCxAyoxwK4sFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"order date" = _t, #"order " = _t, article = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"order date", type date}, {"order ", type text}, {"article", type text}},"de"),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"order ", Text.Trim, type text}, {"article", Text.Trim, type text}}),
    #"Added Custom" = Table.AddColumn(
  #"Trimmed Text", 
  "Price", 
  (k) =>
    Table.SelectRows(
      Prices, 
      each [Article] = k[article] and [valid from] <= k[order date] and k[order date] <= [valid to]
    ){0}[price], 
  Currency.Type
)
in
    #"Added Custom"

 

lbendlin_0-1713969881921.png

 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

Does it need to be DAX?

 

Prices:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hY5RCoAgEESvEn6L7Kwl/tY1xLt5Fk/WalQWmTAsDOxjXggqpymntd4rSiuCkTAxScnJwoBLhVSQinpMciWxGHJN5T8W7vF8rtpDAvPNbp+7tmtMI/Sl7FvlX7g4+76zEzju", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Article = _t, #"valid from" = _t, #"valid to" = _t, price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Article", type text}, {"valid from", type date}, {"valid to", type date}, {"price", Currency.Type}},"de"),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Article", Text.Trim, type text}})
in
    #"Trimmed Text"

Orders:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDSMzDRMzIwMlDSUTq0QKEosdzw0AIIG4gcgexYHYLKnKDKDM31DCxAyoxwK4sFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"order date" = _t, #"order " = _t, article = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"order date", type date}, {"order ", type text}, {"article", type text}},"de"),
    #"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"order ", Text.Trim, type text}, {"article", Text.Trim, type text}}),
    #"Added Custom" = Table.AddColumn(
  #"Trimmed Text", 
  "Price", 
  (k) =>
    Table.SelectRows(
      Prices, 
      each [Article] = k[article] and [valid from] <= k[order date] and k[order date] <= [valid to]
    ){0}[price], 
  Currency.Type
)
in
    #"Added Custom"

 

lbendlin_0-1713969881921.png

 

Greg_Deckler
Community Champion
Community Champion

@LudivineLOU (1) LOOKUPVALUE Range - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors