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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
pilot_butte
Frequent Visitor

Calculation referencing previous row, utilizing the value within the same calculated column

Problem: I need to identify the year that a staff member is hired and assign that date to each subsequent year. However, a staff member can be hired, work for several years, leave and then return.  When the staff member leaves and returns I need to caputure the "new" hire year and assign that value to any year moving forward.  

 

pilot_butte_2-1663556362936.png

 

Current State: I have created a column where I am able to identify the initial hire date for an employee and assign it to every year for that employee. (ex. Employee hired in 2019, employee's hire year will show 2018 for every year 2017-2022) I can also assign the correct year for the year an employee was rehired. However I have been unable to propogate that date to subsequent years.  See the example above.  For this particular employee they were hired in 2017 (Hire Year = 2016).  They left in 2019. However they were rehired in 2021 (Hire Year =2020).  The Hire Year shows correctly in 2021 but incorrectly in 2022 where it still shows 2017. 

 

 

Ask: I need to create a column that shows the most recent hire year taking into account if an employee was hired and then rehired later on. The hire year needs to appear for every year regardless if the employee were employeed during that year.  The hire source needs to be "outside hire" in order for the hire year to change.  The correct outcome for the previously referenced example should look like this. 

pilot_butte_3-1663556656108.png

 

Happy to share part of the dataset but I cannot figure out how to attach it here.

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @pilot_butte ;

You could create a column by dax.

Column = 
VAR _OUT= CALCULATE(MIN('Table'[School Year]),
                    FILTER(ALL('Table'),[StaffUniqueId]=EARLIER('Table'[StaffUniqueId])
                    &&[Hired From]="Outside Hire"
                    &&[Hire Year]>=EARLIER('Table'[Hire Year])))
RETURN IF([School Year]>=_OUT&&_OUT<>BLANK(),_OUT-1,CALCULATE(MIN('Table'[Hire Year]),ALLEXCEPT('Table','Table'[StaffUniqueId])))

The final show:

vyalanwumsft_0-1663657434541.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-yalanwu-msft
Community Support
Community Support

Hi, @pilot_butte ;

Try it.

Column 2 = 
VAR _OUT= CALCULATE(MIN('Table'[School Year]),
                    FILTER('Table',[StaffUniqueId]=EARLIER('Table'[StaffUniqueId])
                    &&[Hired From]="Outside Hire"
                   ))
RETURN 
IF([School Year]<_OUT||_OUT=BLANK(),[School Year]-1,
CALCULATE(MAX('Table'[School Year]),FILTER('Table',[StaffUniqueId]=EARLIER('Table'[StaffUniqueId])&&[School Year]<=EARLIER('Table'[School Year])&&[Hired From]="Outside Hire"))-1)

The final show:

vyalanwumsft_0-1664263005917.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi, @pilot_butte ;

You could create a column by dax.

Column = 
VAR _OUT= CALCULATE(MIN('Table'[School Year]),
                    FILTER(ALL('Table'),[StaffUniqueId]=EARLIER('Table'[StaffUniqueId])
                    &&[Hired From]="Outside Hire"
                    &&[Hire Year]>=EARLIER('Table'[Hire Year])))
RETURN IF([School Year]>=_OUT&&_OUT<>BLANK(),_OUT-1,CALCULATE(MIN('Table'[Hire Year]),ALLEXCEPT('Table','Table'[StaffUniqueId])))

The final show:

vyalanwumsft_0-1663657434541.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yalanwu-msft  This solution worked until I found an edge case where an employee left and was rehired multiple times.  Please see screenshot below.   Therefore the approach of using the minimum no longer yielded accurate results.  Any ideas of how to adjust the formula? 

pilot_butte_1-1664247176706.png

 

This solution worked until I came across a situation where an employee left and returned more than once.  This means that taking the minimum value no longer provides accurate hire year.  Please see below for example.  Please let me know how to modify to account for this situation.

pilot_butte_0-1664246987694.png

 

pilot_butte
Frequent Visitor

@amitchandak stupid question. how do I share data within the forum? 

@pilot_butte , If the sample is on excel copy - Paste. Or have a file on one drive or dropbox and share a link.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

 

StaffUniqueIdSchool YearPositionCategoryDistrict RetainedSchool RetainedHired FromHire_SourceLeft ToHire Year
1221812017Teacher11   2016
1221812018Teacher11   2016
1221812019Teacher11   2016
1221812020Teacher11   2016
1221812021Teacher11   2016
1221812022Teacher     2016
13521132017School Other11   2016
13521132018School Other11   2016
13521132019School Other11   2016
13521132020School Other11   2016
13521132021School Other11   2016
13521132022School Other     2016
1584452017Special Education10  School2016
1584452018Special Education11Other School  2016
1584452019Special Education00  Central_Districts2016
1584452020 00   2016
1584452021Special Education11Outside HireOutside Hire 2020
1584452022Special Education     2016
16992022017 00   2017
16992022018Teacher11Outside HireOutside Hire 2017
16992022019Teacher11   2017
16992022020Teacher11   2017
16992022021Teacher11   2017
16992022022Teacher     2017
17146782017School Other11   2016
17146782018School Other11   2016
17146782019School Other11   2016
17146782020School Other11   2016
17146782021School Other11   2016
17146782022School Other     2016
17652212017School Administration11   2018
17652212018School Administration10  School2018
17652212019School Administration11Other SchoolElementary School 2018
17652212020School Administration11   2018
17652212021School Administration11   2018
17652212022School Administration     2018
18502452017Staff Support00  Central_Districts2016
18502452018 00   2016
18502452019 00   2016
18502452020 00   2016
18502452021 00   2016
19277602017 00   2017
19277602018Teacher11Outside HireOutside Hire 2017
19277602019Teacher11   2017
19277602020Teacher00  Central_Districts2017
19277602021 00   2017
19932242017 00   2017
19932242018Staff Support00Outside HireOutside HireDistrict_Position2017
19932242019School Other11Change PositionParaprofessional (Educational Assistant) 2017
19932242020School Other00  District_Position2017
19932242021Staff Support11Change PositionOther Non-Licensed Staff 2017
19932242022Staff Support     2017
20433192017 00   2018
20433192018 00   2018
20433192019Staff Support11Outside HireOutside Hire 2018
20433192020Staff Support00  Central_Districts2018
20433192021 00   2018
20433192022Staff Support  Outside HireOutside Hire 2021
20671372017 00   2018
20671372018 00   2018
20671372019Student Services11Outside HireOutside Hire 2018
20671372020Student Services00  Central_Districts2018
20671372021 00   2018
22022202017 00   2019
22022202018 00   2019
22022202019 00   2019
22022202020Student Services00Outside HireOutside HireCentral_Districts2019
22022202021 00   2019
23816992017 00   2021
23816992018 00   2021
23816992019 00   2021
23816992020 00   2021
23816992021 00   2021
23816992022School Other  Outside HireOutside Hire 2021
24385772017 00   2021
24385772018 00   2021
24385772019 00   2021
24385772020 00   2021
24385772021 00   2021
24385772022Student Services  Outside HireOutside Hire 2021
2667362017School Administration11   2016
2667362018School Administration00  Central_Districts2016
2667362019 00   2016
2667362020 00   2016
2667362021 00   2016
9636822017Special Education11   2016
9636822018Special Education11   2016
9636822019Special Education11   2016
9636822020Special Education11   2016
9636822021Special Education11   2016
9636822022Special Education     2016
amitchandak
Super User
Super User

@pilot_butte , Can you please share raw data , based on the data we can provide better colution

 

maxx(filter(Table, Table[emp_id] = earlier(Table[Emp_id]) && year([Hire_date]) <=earlier([school_year]) ) , [Hire_date])

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

 

refer 4 ways to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.