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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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