Forum Discussion

ryan_b_fiting's avatar
ryan_b_fiting
Post Patron
3 years ago
Solved

Calculating Counts within a date range PLUS future dates based on Criteria

Hello Community -  I have a pretty complex calculation that I am trying to solve, and have been stuck on this for quite a while!    I am trying to calculate visits that happened within a certain p...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi ryan_b_fiting ,

     

    You could try these measures.

    NPE Date =
    CALCULATE (
        MAX ( 'ENCOUNTERS TABLE'[EncounterDate] ),
        FILTER ( 'ENCOUNTERS TABLE', [EncounterType] = "Acu NPE" )
    )
    
    NPE Date in Appointments =
    CALCULATE (
        MAX ( 'ENCOUNTERS TABLE'[EncounterDate] ),
        FILTER (
            'ENCOUNTERS TABLE',
            [ProviderID] = MAX ( 'APPOINTMENTS TABLE'[ProviderID] )
                && [EncounterType] = "Acu NPE"
        )
    )
    
    Booked/Completed Post NPE =
    IF (
        [NPEs] <> 0,
        CALCULATE (
            COUNT ( 'ENCOUNTERS TABLE'[ProviderID] ),
            FILTER ( 'ENCOUNTERS TABLE', [EncounterDate] > [NPE Date] )
        )
            + CALCULATE (
                COUNT ( 'APPOINTMENTS TABLE'[ProviderID] ),
                FILTER (
                    'APPOINTMENTS TABLE',
                    [AppointmentDate] > [NPE Date in Appointments]
                        && [ProviderID] = MAX ( 'ENCOUNTERS TABLE'[ProviderID] )
                )
            ),
        0
    )
    

    The two dates are measured by comparing dates with the APPOINTMENTS table and the ENCOUNTERS table, respectively.

     

     

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.