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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Beavertron
Frequent Visitor

Measure to count active employees in a period based on Slicer Calendar

Hi,

 

I have a table which contains employees DateStarted and Leavedates. Leavedates is NULL if they are still active. In SQL I would run a where statement based on SSRS date parameters to only include active in a month period for example,

 

where (LeaveDate >= @datefrom and DateStarted < @dateto) or (DateStarted < @dateto and LeaveDate is NULL)

so if I replace the parameters with dates

where (LeaveDate >= '01 May 2020' and DateStarted < '01 Jun 2020) or (DateStarted < '01 Jun 2020) and LeaveDate is NULL)

... so this captures anyone who were active for any portion of this month for example, or even start before and finish after etc.

 

I am struggling to convert this to a measure so I can display a count of employees on a 3D card, based on a date slider linked to a calendar table, making this value dynamic. Thank you in advance.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Beavertron 

Use the following measure to get the active employees to count. Modify the table name and field names as per your model.

Employee Count = 
VAR __DATE = MAX ( 'Date'[Date] )
RETURN
    SUMX (
        EmployeeTable,
        IF (
            EmployeeTable[DateStarted] <= __DATE
                && OR ( EmployeeTable[Leavedates] >= __DATE , ISBLANK(EmployeeTable[Leavedates]) ),
            1,
            BLANK ()
        )
    )
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

1 REPLY 1
Fowmy
Super User
Super User

@Beavertron 

Use the following measure to get the active employees to count. Modify the table name and field names as per your model.

Employee Count = 
VAR __DATE = MAX ( 'Date'[Date] )
RETURN
    SUMX (
        EmployeeTable,
        IF (
            EmployeeTable[DateStarted] <= __DATE
                && OR ( EmployeeTable[Leavedates] >= __DATE , ISBLANK(EmployeeTable[Leavedates]) ),
            1,
            BLANK ()
        )
    )
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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