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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Coffee321
Frequent Visitor

Lookup value from another table based on key match and nearest date match

I'm trying to bring a value from another table but there is no relationship because of duplicates. This is the Dim table, the value I'm trying to bring over is on the PerUnit column:


Coffee321_2-1722259013896.png



I'm trying to create a calculated column on the fact table that will bring the PerUnit value based on an Item match and the closest date match from the Dim table. The FactTable looks like this:


Coffee321_4-1722259060807.png



The calculated column would look like this

Coffee321_5-1722259090987.png



I've tried using lookupvalue and other measures to achieve this but haven't been able to. The dim table contains hundreds of items, converting the dim table into a proper dim table that will allow me to connect it to the fact table has been challenging ( hence the approach of a calculated column). Any help will be greatly appreciated.



1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Coffee321 

you can create a column

 

Column =
var _last=maxx(FILTER(Dim,'Dim'[Date]<='Fact'[Date]&&'Fact'[Item]=Dim[Item]),'Dim'[Date])
return maxx(FILTER(Dim,'Dim'[Item]='Fact'[Item]&&'Dim'[Date]=_last),Dim[PerUnit])
 
11.PNG
 
or create a measure
 
Measure =
var _last=maxx(FILTER(all(Dim),'Dim'[Date]<=max('Fact'[Date])&&Dim[Item]=max('Fact'[Item])),'Dim'[Date])
return maxx(FILTER(all(Dim),Dim[Item]=max('Fact'[Item])&&'Dim'[Date]=_last),'Dim'[PerUnit])
 
12.PNG
pls see the attachment below




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
ryan_mayu
Super User
Super User

@Coffee321 

you can create a column

 

Column =
var _last=maxx(FILTER(Dim,'Dim'[Date]<='Fact'[Date]&&'Fact'[Item]=Dim[Item]),'Dim'[Date])
return maxx(FILTER(Dim,'Dim'[Item]='Fact'[Item]&&'Dim'[Date]=_last),Dim[PerUnit])
 
11.PNG
 
or create a measure
 
Measure =
var _last=maxx(FILTER(all(Dim),'Dim'[Date]<=max('Fact'[Date])&&Dim[Item]=max('Fact'[Item])),'Dim'[Date])
return maxx(FILTER(all(Dim),Dim[Item]=max('Fact'[Item])&&'Dim'[Date]=_last),'Dim'[PerUnit])
 
12.PNG
pls see the attachment below




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
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.