Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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
Solved! Go to Solution.
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
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
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!
User | Count |
---|---|
42 | |
28 | |
23 | |
18 | |
16 |
User | Count |
---|---|
54 | |
35 | |
18 | |
18 | |
15 |