Forum Discussion

ConnieMaldonado's avatar
ConnieMaldonado
Icon for Responsive Resident rankResponsive Resident
5 years ago
Solved

Calculate Max Date by Employee Number

Hello - I need to create a filter to determine the max date by employee ID for a table which has the following:

 

RVPRDOLocation  DATETech NameEmployee Number
RVP 1RDO 1Norfolk1/16/2021Doe, John149531
RVP 1RDO 1Norfolk1/18/2021Doe, John149531
RVP 1RDO 1Norfolk12/29/2020Doe, John149531
RVP 1RDO 1Norfolk12/30/2020Doe, John149531
RVP 1RDO 1Norfolk12/31/2020Doe, John149531
RVP 1RDO 2VA Beach1/5/2021Morgan, Terry123456
RVP 1RDO 2VA Beach1/6/2021Morgan, Terry123456
RVP 1RDO 2VA Beach1/7/2021Morgan, Terry123456
RVP 1RDO 2VA Beach1/8/2021Morgan, Terry123456

 

I want to return the max date by employee number.  I tried the following:

Max Date = MAX(MAX('Table','Table'[DATE])) and MAXX(MAX('Table','Table'[DATE]))

 

but that returned the date.

Any help would be appreciated.  Thanks!

  • ConnieMaldonado use this expression:

     

    Max Date = CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Employee Number] ) )

     

    Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

5 Replies

  • ConnieMaldonado use this expression:

     

    Max Date = CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Employee Number] ) )

     

    Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • ConnieMaldonado's avatar
      ConnieMaldonado
      Icon for Responsive Resident rankResponsive Resident

      Thank you - one more question.  I have a measure to calculate Total Hours for each employee and would like to include a filter so that I'm calculating the max date for all the records for the employee for which Total Hours > 0.  I have a filter on the visual, so I'm not sure why that doesn't work.  Can I add a filter to the ALLEXCEPT statement?

  • ConnieMaldonado if Total Hours is a column, make this change

     

    Max Date = 
    CALCULATE ( 
    MAX ( 'Table'[Date] ), 
    ALLEXCEPT ( 'Table', 'Table'[Employee Number] ) 
    'Table'[Total Hours] > 0
    )

     

    Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • ConnieMaldonado's avatar
      ConnieMaldonado
      Icon for Responsive Resident rankResponsive Resident

      Unfortunately, Total Hours is a measure.  I tried the statement above, but of course Total Hours is not allowed in the expression.  I've tried several different things to no avail. 

  • ConnieMaldonado's avatar
    ConnieMaldonado
    Icon for Responsive Resident rankResponsive Resident

    I got this to work.  I was able to create a column for the hours and used your code above!  Thanks!  You're the best.

     

    Max Date =
    CALCULATE (
    MAX ( 'Table'[Date] ),
    ALLEXCEPT ( 'Table', 'Table'[Employee Number] ) ,
    'Table'[Total Hours] > 0
    )