Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
gftx90
Frequent Visitor

Distinct Values in T1 not in T2 with bi-directional slowly changing dimension

Hello PBI community,

 

I am so stuck.

 

I have an overtime model which contains the following tables

  1. Fact Overtime - recieves daily instances of overtime
  2. DimTeamMember - type 2 changing dimension, updates with changes of attributes. most current has IsActive value of "Yes"
  3. DimTeamMemberList - distinct list of team members to resolve the M:N between tables 1 and 2
  4. Dim Date

All visible columns are keys.

Screenshot 2022-01-11 013958.png

I am having a lot of trouble getting a count of active team members that are in table 2 but not table 1 (the ones that did not work overtime), especially when grouped by their respective division. I have managed to create a measure that works as a stand alone calculation with this code...

TEST = 
VAR A = MIN('DimDate'[Date])
VAR B = 
CALCULATETABLE(
    VALUES('DimTeamMember'[EmployeeSK]), 
    CROSSFILTER('DimTeamMember'[EmployeeSK],'DimTeamMemberList'[EmployeeSK], NONE),
    'DimTeamMember'[IsActive] = "Yes", 
    OR('DimTeamMember'[TerminationDate] >= a, 'DimTeamMember'[TerminationDate] = blank())
    )
VAR C = CALCULATETABLE(VALUES('FactOvertime'[EmployeeSK]))
VAR D = COUNTROWS( DISTINCT(EXCEPT(B, C)))
RETURN D 

 

but this measure falls short as I cant break down this total by division. here is an example.

Screenshot 2022-01-11 021039.png

I believe the way the model relationships are set up is necessary for other aspects of reporting because the historical team member dimension is a special case with many attributes.

Is there a way to solve this with dax? 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @gftx90 ,

I created a sample pbix file(see attachment), please check whether that is what you want. I updated the formula of your measure [TEST] as below:

TEST = 
VAR _curdate =
    SELECTEDVALUE ( 'DimDate'[Date] )
VAR _tmembers =
    CALCULATETABLE (
        VALUES ( 'DimTeamMember'[EmployeeSK] ),
        FILTER (
            'DimTeamMember',
            'DimTeamMember'[IsActive] = "Yes"
                && (
                    ISBLANK ( 'DimTeamMember'[TerminationDate] )
                        || IF (
                            NOT ( ISBLANK ( 'DimTeamMember'[TerminationDate] ) ),
                            'DimTeamMember'[TerminationDate] >= _curdate
                        )
                )
        )
    )
VAR _otmembers =
    CALCULATETABLE ( VALUES ( 'FactOvertime'[EmployeeSK] ) )
VAR _ncount =
    COUNTROWS ( DISTINCT ( EXCEPT ( _tmembers, _otmembers ) ) )
RETURN
    _ncount

yingyinr_0-1642152121847.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @gftx90 ,

I created a sample pbix file(see attachment), please check whether that is what you want. I updated the formula of your measure [TEST] as below:

TEST = 
VAR _curdate =
    SELECTEDVALUE ( 'DimDate'[Date] )
VAR _tmembers =
    CALCULATETABLE (
        VALUES ( 'DimTeamMember'[EmployeeSK] ),
        FILTER (
            'DimTeamMember',
            'DimTeamMember'[IsActive] = "Yes"
                && (
                    ISBLANK ( 'DimTeamMember'[TerminationDate] )
                        || IF (
                            NOT ( ISBLANK ( 'DimTeamMember'[TerminationDate] ) ),
                            'DimTeamMember'[TerminationDate] >= _curdate
                        )
                )
        )
    )
VAR _otmembers =
    CALCULATETABLE ( VALUES ( 'FactOvertime'[EmployeeSK] ) )
VAR _ncount =
    COUNTROWS ( DISTINCT ( EXCEPT ( _tmembers, _otmembers ) ) )
RETURN
    _ncount

yingyinr_0-1642152121847.png

Best Regards

amitchandak
Super User
Super User

@gftx90 , Refer if the HR blog's current employee logic can help

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.