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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Lookupvalue on date period

Hi,

 

I have been searching for ways to lookup a value (for instance a costprice) from another table based on a time interval. 

 

Sales Table                                                                 PriceTable

Date                    Product                                           Product               StartDate              EndDate            Cost

2019-01-01               A                                                     A                   2019-01-01           2019-01-31         5

2019-01-01               B                                                     B                   2019-01-01            2019-01-31         8

2019-01-02               A                                                     A                   2019-02-01            2019-02-28        7

2019-02-01               A                                                     

 

 

Desired outcome

SalesTable

Date                    Product         Price                                  

2019-01-01               A                 5                           

2019-01-01               B                 8                               

2019-01-02               A                 5                               

2019-02-01               A                 7   

 

I have no problems getting the price for the first of every month as those dates correspond with each other. But what I would like is for the sale on the second to lookup the corresponding cost price based on the price in the interval 2019-01-01 - 2019-01-31. How does one best set this up? Some use of minx/maxx? TopN?

 

I managed to solve it by creating a helper table listing all dates between the intervall and adding the cost price on each date for each item. But this table grows quickly, and the sollution is not very neat. I am sure there are better and faster ways to do this.

 

I don't mind if the sollution is given as a calculated column or a measure. Any way that is better than the list of all possible dates/items/costs would work.

 

Thank you,

Kind regards,

Patrik

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

try new measure in the Sales table

Measure = calculate(MAX('Price Table'[Cost]);
FILTER(ALL('Price Table');
'Price Table'[Product]=Selectedvalue('Sales Table'[Product]) &&
'Price Table'[StartDate]<=selectedvalue('Sales Table'[Date]) && 
'Price Table'[EndDate]>=selectedvalue('Sales Table'[Date])
)
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
Linkedin


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

2 REPLIES 2
az38
Community Champion
Community Champion

Hi @Anonymous 

try new measure in the Sales table

Measure = calculate(MAX('Price Table'[Cost]);
FILTER(ALL('Price Table');
'Price Table'[Product]=Selectedvalue('Sales Table'[Product]) &&
'Price Table'[StartDate]<=selectedvalue('Sales Table'[Date]) && 
'Price Table'[EndDate]>=selectedvalue('Sales Table'[Date])
)
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
Linkedin


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thank you very much @az38 .

 

Tried it out this morning, and so far it looks to be doing what I want it too, and could even add some more filtering I needed. Very clean sollution, big thanks!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.