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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Deva002
Frequent Visitor

Count function with an expression

Hi All,

 

I came across a very simple - complex (pardox) situation. I have a table like the below one with Emp_ID, Joining Date & Relieving Date with 5000 employee records for the last 20 years. I need to get a Monthly headcount report where a person has to be joined before the selected month and not relieved that month.

 

 

Emp_IDJoining DateRelieving Date
   
   

 

Deva

1 ACCEPTED SOLUTION
Eric_Zhang
Microsoft Employee
Microsoft Employee

@Deva002

 

You need a calendar table and a measure like

 

headcount = 
COUNTAX (
    FILTER (
        ALL ( Employees ),
        Employees[Joining Date] <= MAX ( CalendarTbl[MonthEnd] )
            && (
                Employees[Relieving Date] > MAX ( CalendarTbl[MonthEnd] )
                    || ISBLANK ( Employees[Relieving Date] )
            )
    ),
    Employees[Emp_ID]
)

Dataset

Capture.PNG

 

Capture.PNG

Capture.PNG

 

 

C

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@Deva002

 

You need a calendar table and a measure like

 

headcount = 
COUNTAX (
    FILTER (
        ALL ( Employees ),
        Employees[Joining Date] <= MAX ( CalendarTbl[MonthEnd] )
            && (
                Employees[Relieving Date] > MAX ( CalendarTbl[MonthEnd] )
                    || ISBLANK ( Employees[Relieving Date] )
            )
    ),
    Employees[Emp_ID]
)

Dataset

Capture.PNG

 

Capture.PNG

Capture.PNG

 

 

C

KGrice
Memorable Member
Memorable Member

Hi @Deva002. Could you provide some clarification with an example? If Emp_ID 123 has a joining date of 1 June 2016 and a relieving date of 1 August 2016, they would contribute to the headcount for only the month of July 2016. However, if they joined any time in May 2016, they should contribute to the headcount for June and July 2016. Is that accurate?

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.