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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors