Forum Discussion

jonnyA's avatar
jonnyA
Responsive Resident
5 years ago
Solved

Formula for pulling most recent patient visit

Hello!

Looking for help to create a formula that will bring back the most recent patient visit.  For example, I have an excel file with 20,000 patient names, many of the patients are listed multiple times because they had multiple visits.  How would I create a formula that will only bring back the most recent visit?  Below are the fields I am using.  Thank you in advance!

 

 

  • Thanks to everyone who responded!

    I figured out the answer ...

    Max Date = (MAX('ApptDetail'[Appt DateTime]))

3 Replies

  • jonnyA , Create a measure like this and try

     

    Measure =
    VAR __id = MAX ('Table'[Patient Last Name, First Name] )
    VAR __date = CALCULATE ( MAX('Table'[App Date Time] ), ALLSELECTED ('Table' ), 'Table'[Patient Last Name, First Name] = __id )
    CALCULATE ( MAx ('Table'[App Date Time] ), VALUES ('Table'[Patient Last Name, First Name] ),'Table'[Patient Last Name, First Name] = __id,'Table'[App Date Time] = __date )

  • BI_Jo's avatar
    BI_Jo
    Resolver III

    Hi 

     

    I would create a latest visit column using the following DAX and use the column as a filter on your report:

    LatestVisitColumn =
    if('TableName'[Appt DateTime] = CALCULATE(MAX('TableName'[Appt DateTime]),
    ALLEXCEPT('TableName','TableName'[Patient ID Field])), "Yes", "No")

    The column will say "Yes" if it is the patients latest visit. 
     
    Hope that helps
    Jo
  • jonnyA's avatar
    jonnyA
    Responsive Resident

    Thanks to everyone who responded!

    I figured out the answer ...

    Max Date = (MAX('ApptDetail'[Appt DateTime]))