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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Miles1987
Frequent Visitor

Active employees in a period

Hi

I have a dax for a KPI that I can’t seem to make work. What I want is to count, the number og employees that has been active every month in the filtered period. The data looks like this:

Miles1987_0-1649065736662.png

 

I figured that I need to know how many months are in the period, I did that this way
V – Number of months= CALCULATE(DISTINCTCOUNT('HRPM SKF'[ID]), ALLEXCEPT('HRPM SKF','HRPM SKF'[EOM]))

This work fine, but I can’t make a dax that counts how many employees that has been active every month in the filtered period.

I tried with:

V – Number of employees  =

Var months = V – Number of months

Var number = DISTINCTCOUNT('HRPM SKF'[Medarbejdernr-W (HRPM)])

 

Return

if(number=moths,1,0)

 

This works fine, when I do a list with employee IDs in it. But not when I aggregate in a KPI.
Jesper

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I suggest having a dim-calendar table like below.

 

Picture1.png

 

Active employee count: = 
VAR employeetable =
    ADDCOLUMNS (
        VALUES ( Data[ID] ),
        "@startdate", CALCULATE ( MIN ( Data[EOM] ) ),
        "@enddate", CALCULATE ( MAX ( Data[EOM] ) )
    )
RETURN
        COUNTROWS (
            FILTER (
                employeetable,
                [@startdate] <= MAX ( 'Calendar'[Date] )
                    && [@enddate] >= MIN ( 'Calendar'[Date] )
            )
        )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I suggest having a dim-calendar table like below.

 

Picture1.png

 

Active employee count: = 
VAR employeetable =
    ADDCOLUMNS (
        VALUES ( Data[ID] ),
        "@startdate", CALCULATE ( MIN ( Data[EOM] ) ),
        "@enddate", CALCULATE ( MAX ( Data[EOM] ) )
    )
RETURN
        COUNTROWS (
            FILTER (
                employeetable,
                [@startdate] <= MAX ( 'Calendar'[Date] )
                    && [@enddate] >= MIN ( 'Calendar'[Date] )
            )
        )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


tamerj1
Super User
Super User

Hi @Miles1987 

did you try simple DISTINCTCOUNT?

Number Of Employees =

DISTINCTCOUNT('HRPM SKF'[ID])

Yes. however i only wanna count them if they have been active every month in the periode.  Lets say i set my period filter to "From 30-06-2021 to 31-07-2021" then it should 2. Because only James and Ivan have been acticve in both months  

@Miles1987 

Then you just need to create new measure

Number Of Employees =

DISTINCTCOUNT('HRPM SKF'[ID])

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors