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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
afhs
Regular Visitor

Nearest previous date

Hi,

I have two tables witg data about locations and tasks. I'm trying to import from Table2, the nearest previous date based on the planned date on Table1 for the Location.
Any ideas on how can I find the nearest previous date from another column based on the "Location"? 

Table1

LocationTaskPlanned Date
Home 1Cleaning03-12-2019
Home 1Painting19-12-2019
Home 2Painting05-12-2019
Home 2Mowing29-12-2019
Home 3Cleaning17-12-2019
Home 5Cleaning18-12-2019
Home 7Mowing22-12-2019
Home 8Mowing29-12-2019

 

Table2

LocationTask Completition
Home 101-12-2019
Home 115-12-2019
Home 201-12-2019
Home 223-12-2019
Home 312-12-2019
Home 514-12-2019
Home 719-12-2019
Home 823-12-2019

 

The resulting table should looks as follow:

 

LocationTaskPlanned DateTask Completition
Home 1Cleaning03-12-201901-12-2019
Home 1Painting19-12-201915-12-2019
Home 2Painting05-12-201901-12-2019
Home 2Mowing29-12-201923-12-2019
Home 3Cleaning17-12-201912-12-2019
Home 5Cleaning18-12-201914-12-2019
Home 7Mowing22-12-201919-12-2019
Home 8Mowing29-12-201923-12-2019

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@afhs Please use below measure to get the latest completion date

Measure = 
VAR _location = MAX(Table1[Location])
VAR _plannedDate = MAX(Table1[Planned Date])
RETURN CALCULATE(MAX(Table2[Task Completition]),Table2[Location]=_location,Table2[Task Completition]<=_plannedDate)

If it helps accept solution. 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

@afhs Please use below measure to get the latest completion date

Measure = 
VAR _location = MAX(Table1[Location])
VAR _plannedDate = MAX(Table1[Planned Date])
RETURN CALCULATE(MAX(Table2[Task Completition]),Table2[Location]=_location,Table2[Task Completition]<=_plannedDate)

If it helps accept solution. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.