Forum Discussion

AbhinavJoshi's avatar
AbhinavJoshi
Icon for Responsive Resident rankResponsive Resident
2 years ago
Solved

Calculate Year over Year Count

Hello, I have the following dataset  Clients Table ClientID, MonthsActive, YearsActive, IsTerminated, TotalLives, SizeBand, TerminationDate, EnrollmentDate. If the client is still active the Is...
  • danextian's avatar
    danextian
    2 years ago

    Hi AbhinavJoshi ,

     

    Create a separate dates table:

    Dates = 
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2007, 1, 1 ), TODAY () ),
        "Year", YEAR ( [Date] ),
        "YYYYMM", FORMAT ( [Date], "YYYYMM" )
    )
    

    Link this to Enrollment date (active relationship) and Termination Date (inactive) usingi a one to many single direction relationship.

     

    Create these measures:

    Enrolled = 
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER ( ALL ( Dates ), Dates[Date] <= MAX ( Dates[Date] ) )
    )
    
    Terminated = 
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( Dates ),
            Dates[Date] <= MAX ( Dates[Date] )
                && NOT ( ISBLANK ( Dates[Date] ) )
        ),
        USERELATIONSHIP ( Dates[Date], 'Table'[TerminationDate] )
    )
    
    Active = 
    [Enrolled] - [Terminated]

     

    Or you can put them in one measure instead. I separate them so you can see what happens for each.

    I modified your sample data a bit by adding an extra termination date for Account2. Please refer to the attached pbix for the details.