Forum Discussion

aflintdepm's avatar
aflintdepm
Helper III
2 years ago
Solved

Next Visit Type by Visit Date

I have a table of client visits and visit dates (all future).  There are multiple visit types that could be scheduled, but I would like to report what the next visit type is, not the when.

 

Here is a small sample:

Patient NameVisit TypeVisit Date
John SmithRegular7/25/2024
Betty JonesAnnual8/1/2024
Bob JohnsonRegular7/10/2024
John SmithAnnual8/25/2024
Betty JonesRegular9/1/2024
Bob JohnsonAnnual8/15/2024

 

For this example, I would like the results to look like this:

Patient NameNext Scheduled Visit Type
John SmithRegular
Betty JonesAnnual
Bob JohnsonRegular

 

I know how to calculate when the next visit is, but I don't know how to return the value in Visit Type based on that calculation.

 

Any and all help appreciated.  Thank you

  • Hi aflintdepm 

     

    Would a measure like this help?

    Next Visit Type = 
    VAR _NextDate =
        CALCULATE(
            MIN( 'Table'[Visit Date] ),
            'Table'[Visit Date] > TODAY()
        )
    VAR _NextType =
        CALCULATE(
            MAX( 'Table'[Visit Type] ),
            'Table'[Visit Date] = _NextDate
        )
    RETURN
    	_NextType

1 Reply

  • Hi aflintdepm 

     

    Would a measure like this help?

    Next Visit Type = 
    VAR _NextDate =
        CALCULATE(
            MIN( 'Table'[Visit Date] ),
            'Table'[Visit Date] > TODAY()
        )
    VAR _NextType =
        CALCULATE(
            MAX( 'Table'[Visit Type] ),
            'Table'[Visit Date] = _NextDate
        )
    RETURN
    	_NextType