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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Glenda
Helper I
Helper I

Finding the value based off date and ID

Hi, 

 

Ok, I am sure this is not a hard one but I just can' get it so hoping someone can help me out. I need to find the cost centre a person worked for when they had an injury. I have 2 tables: 

  1. The business table which has the employee ID, Cost Centre and Date (AWD Date From) 
  2. Injury table with the employee ID and date of injury (DOI).

I need to find the Cost Centre at the time of the injury. 

 

Business Table

Employee IDCost CentreAWD Date From
12345642252601/09/2007
12345620252606/07/2009
12345610162208/12/2014
12345620252608/01/2018
12345620017504/11/2019
98745616923520/12/2007
98745616923726/05/2008
98745616920722/12/2008
98745616924121/12/2009
98745616920925/10/2010
98745616924229/12/2014
98745674333618/06/2018
98745674333622/06/2020

 

Injury Table

Employee IDDOI
12345608/03/08
12345603/09/11
12345627/12/15
12345606/07/20
98745621/12/08
98745622/12/08

 

The output I need is the injury table plus the cost where the employee was working at the date of injury like the table below. 

Employee IDDOICost Centre
12345608/03/08422526
12345603/09/11202526
12345627/12/15101622
12345606/07/20200175
98745621/12/08169237
98745622/12/08169207

 

Here is a link to my pbix with the data loaded - https://ufile.io/3oen7t5r

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

Thanks for providing a pbix file.  Here is an expression you can use in a new DAX column on your Injury Dates table, to get the Employees cost center at the time.

 

DOI Cost Center =
VAR __thisemployee = 'Injury dates'[Employee ID]
VAR __thisdate = 'Injury dates'[DOI]
VAR __CCdate =
    CALCULATE (
        MAX ( business[AWD Date From] ),
        business[AWD Date From] <= __thisdate,
        business[Employee ID] = __thisemployee
    )
RETURN
    CALCULATE (
        MIN ( business[Cost Centre] ),
        business[Employee ID] = __thisemployee,
        business[AWD Date From] = __CCdate
    )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Thank you so much it works perfectly 😄  

View solution in original post

2 REPLIES 2
mahoneypat
Employee
Employee

Thanks for providing a pbix file.  Here is an expression you can use in a new DAX column on your Injury Dates table, to get the Employees cost center at the time.

 

DOI Cost Center =
VAR __thisemployee = 'Injury dates'[Employee ID]
VAR __thisdate = 'Injury dates'[DOI]
VAR __CCdate =
    CALCULATE (
        MAX ( business[AWD Date From] ),
        business[AWD Date From] <= __thisdate,
        business[Employee ID] = __thisemployee
    )
RETURN
    CALCULATE (
        MIN ( business[Cost Centre] ),
        business[Employee ID] = __thisemployee,
        business[AWD Date From] = __CCdate
    )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you so much it works perfectly 😄  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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
Top Kudoed Authors