cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
afhs Visitor
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

Accepted Solutions
Super User II
Super User II

Re: Nearest previous date

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





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
Super User II
Super User II

Re: Nearest previous date

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





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

Proud to be a Super User!




View solution in original post

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors