Forum Discussion

pilot_butte's avatar
pilot_butte
Frequent Visitor
3 years ago
Solved

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.  

 

 

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. 

 

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

  • 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:


    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.

8 Replies

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    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:


    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.

    • pilot_butte's avatar
      pilot_butte
      Frequent Visitor

      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's avatar
      pilot_butte
      Frequent Visitor

      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? 

       

    • amitchandak's avatar
      amitchandak
      Super User

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

      • pilot_butte's avatar
        pilot_butte
        Frequent Visitor

         

        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
  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    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:


    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.