Forum Discussion
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 reporting to a diffrent manager, in this case we dont need to loose the historical data that belonged to the previous manager when the employee was reporting to him. So we have introduced an effective end date concept. The tables looks like this.
User :
| User | Manager | Effective EndDate |
| A | B | 1/2/2022 |
| A | C | |
| D | B |
Fact Table :
| User | Date | Count |
| A | 1/1/2022 | 10 |
| A | 1/2/2022 | 20 |
| A | 1/7/2022 | 30 |
| A | 1/8/2022 | 10 |
| D | 1/1/2022 | 10 |
| D | 1/4/2022 | 20 |
Apart from this we have a date table for date slicer.
We need to Build a matrix like below.
Date Range Selected : 01/01/2022 to 01/10/2022 in Slicer
| User | Manager | Count |
| A | B | 30 |
| A | C | 40 |
| D | B | 30 |
Would you be able to help me to build a measure to acheive this .?
Thanks.
Regards,
Aju P Sebastian
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 vResultCount 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
1 Reply
- DataInsights
Super User
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 vResultCount 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