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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors