Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Effective Dated User Table with manager Information

Hi all,   I have a requirement to display the count of a measure per employee and per Manager in a power BI dashboard. The manager information can be changed at anytime and the employee can be repo...
  • DataInsights's avatar
    4 years ago

    Anonymous,

     

    This solution requires a slight change to the User table. If you restructure it to use Start Date and End Date, it simplifies the DAX:

     

     

    Create a bridge table using DAX (calculated table):

     

    DistinctUser = DISTINCT ( User[User] )

     

    Create relationships as shown below. If you prefer not to use a bidirectional relationship between User and DistinctUser, you can use USERELATIONSHIP in the measure (and specify bidirectional).

     

     

    Use either of the measures below (you can try both to see which is more performant):

     

    Count CALCULATE = 
    VAR vStartDate =
        MAX ( User[Start Date] )
    VAR vEndDateCol =
        MAX ( User[End Date] )
    VAR vEndDate =
        IF ( ISBLANK ( vEndDateCol ), DATE ( 9999, 12, 31 ), vEndDateCol )
    VAR vAmount =
        CALCULATE ( SUM ( FactTable[Count] ),
            FactTable[Date] >= vStartDate,
            FactTable[Date] <= vEndDate
            )
    // calculate total
    VAR vResult =
        IF ( HASONEVALUE ( User[User] ), vAmount, SUM ( FactTable[Count] ) )
    RETURN
        vResult

     

    Count SUMX = 
    VAR vStartDate =
        MAX ( User[Start Date] )
    VAR vEndDateCol =
        MAX ( User[End Date] )
    VAR vEndDate =
        IF ( ISBLANK ( vEndDateCol ), DATE ( 9999, 12, 31 ), vEndDateCol )
    VAR vAmount =
        SUMX (
            FactTable,
            IF (
                FactTable[Date] >= vStartDate
                    && FactTable[Date] <= vEndDate,
                FactTable[Count]
            )
        )
    // calculate total
    VAR vResult =
        IF ( HASONEVALUE ( User[User] ), vAmount, SUM ( FactTable[Count] ) )
    RETURN
        vResult