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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
metcala
Helper III
Helper III

Filtering by the most recent date across 2 tables

Hi

 

I've spent a bit of time looking through the forum to try and find a solution that helps solve my problem to no avail!

 

Essentially I have a Role table:

 

Role ID
1001
1002
...

 

And I want to be able to add the current employee or vacancy.

 

Staff IDRole IDStart DateEnd Date
1001.........
1002.........

 

Vacancy IDRole IDStart DateEnd Date
1001.........
1002.........

 

My current thinking is to add a column onto the Role table looking up the last entry from each table. A slight complication is that some roles are pre filled in the future so would have to be up to the current date.

 

I've spent a while trying to get this working and any guidance as to whether this is a sensible approach or where/how to solve it would be very much appreciated!

 

Thanks in advance!

1 ACCEPTED SOLUTION

Hi, @metcala 

Please try formula like:

Vacancy ID = 
VAR _MAXDATE=CALCULATE(MAX('Table 2'[Start Date]),ALLEXCEPT('Table 2','Table 2'[Role ID]))
RETURN  CALCULATE(MAX('Table 2'[Vacancy ID]),FILTER(ALL('Table 2'),'Table 2'[Start Date]=_MAXDATE&&'Table 2'[Role ID]=MAX('Role table'[Role ID])))
Staff ID = 
VAR _MAXDATE=CALCULATE(MAX('Table 1'[Start Date]),ALLEXCEPT('Table 1','Table 1'[Role ID]))
RETURN  CALCULATE(MAX('Table 1'[Staff ID]),FILTER(ALL('Table 1'),'Table 1'[Start Date]=_MAXDATE&&'Table 1'[Role ID]=MAX('Role table'[Role ID])))

If it doesn‘t work, please share a sample file and expected outcome in excel for further research.

Best Regards,
Community Support Team _ Eason


 

View solution in original post

4 REPLIES 4
metcala
Helper III
Helper III

@daXtreme @amitchandak 

 

Thanks for your replies and apologies if my explanation wasn't clear!

 

I am looking to add a column showing either the current Staff ID or Vacancy ID. So for the example below Role 101 should show V002.

 

Staff IDRole IDStart DateEnd Date
S0011011/8/202031/10/2022

 

Vacancy IDRole IDStart DateEnd Date
V0011011/1/202031/7/2020
V0021011/11/2022 

Hi, @metcala 

Please try formula like:

Vacancy ID = 
VAR _MAXDATE=CALCULATE(MAX('Table 2'[Start Date]),ALLEXCEPT('Table 2','Table 2'[Role ID]))
RETURN  CALCULATE(MAX('Table 2'[Vacancy ID]),FILTER(ALL('Table 2'),'Table 2'[Start Date]=_MAXDATE&&'Table 2'[Role ID]=MAX('Role table'[Role ID])))
Staff ID = 
VAR _MAXDATE=CALCULATE(MAX('Table 1'[Start Date]),ALLEXCEPT('Table 1','Table 1'[Role ID]))
RETURN  CALCULATE(MAX('Table 1'[Staff ID]),FILTER(ALL('Table 1'),'Table 1'[Start Date]=_MAXDATE&&'Table 1'[Role ID]=MAX('Role table'[Role ID])))

If it doesn‘t work, please share a sample file and expected outcome in excel for further research.

Best Regards,
Community Support Team _ Eason


 

daXtreme
Solution Sage
Solution Sage

Sorry, but this explanation is unclear.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors