Forum Discussion

jmilne320's avatar
jmilne320
Frequent Visitor
4 years ago
Solved

Count staff that move between roles

Hi All,   I am new to Power BI and I am struggling to create a measure that counts staff of different categories on a particular date.   My model is as below:   The 'Events' table records...
  • tamerj1's avatar
    4 years ago

    Hi jmilne320 
    I hope this is what you're looking for

    Active Staff = 
    CALCULATE ( 
        COUNTROWS (
            FILTER (
                CALCULATETABLE (
                    Pilots,
                    CROSSFILTER ( Pilots[Staff Number], events[Staff Number], BOTH )
                ),
                MAXX ( RELATEDTABLE ( Events ), Events[Date] ) <= MAX ( 'Date'[Date] )
            )
        ),
        'Date'[date] <= MAX ('Date'[date] )
    )

  • tamerj1's avatar
    tamerj1
    4 years ago

    Hi jmilne320 
    First you need to create a new column for end date in the vents table:

    end date = 
    MINX ( 
        FILTER ( 
            CALCULATETABLE ( Events, ALLEXCEPT ( Events, Events[Staff Number] ) ), 
            Events[start date] > EARLIER ( Events[start date] ) 
        ), 
        Events[start date] 
    )

    Then you need to deactivate or delete the relationship with the date table

    The following would be the measure

    Active Staff = 
    VAR CurrentDate = MAX ( 'Date'[date] )
    RETURN
        COUNTROWS (
            FILTER (
                Events,
                VAR StartDate = Events[start date] 
                VAR EndtDate = COALESCE ( Events[End date], DATE ( 3000, 1, 1 ) )
                RETURN
                    StartDate <= CurrentDate
                        && EndtDate >= CurrentDate
            )
        )