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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Count is different. I want to calculate headcount as per the date selected.

Dear Folk,

 

Please help me i am trying to calculate the headcount from the start date to the last date of the selected year and month. 

 

kindly check the below DAX function I have used. 

for Working count:-

Working_MTD = CALCULATE('Measure Organize'[empCount],'Employee Dump'[STATUS]="Working",DATESBETWEEN(Date_Table[Date],'Measure Organize'[minDate],'Measure Organize'[endDate]))

gauravtomar_0-1659613945285.png

The above table is showing working MTD head count but in august which is the current month and the total is showing different.

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

 

It is suggested to create a seperate year and month table for the slicer.

You can create a yearmonth table like

 

 

YearMonth =
DISTINCT (
    SELECTCOLUMNS (
        'Date_Table',
        "Year", YEAR ( [Date] ),
        "Month", MONTH ( [Date] )
    )
)

 

Then create the Working_MTD measure like

 

Working_MTD = 
VAR _year =
    SELECTEDVALUE ( YearMonth[Year] )
VAR _month =
    SELECTEDVALUE ( YearMonth[Month] )
RETURN
    CALCULATE (
        [empCount],
        FILTER ( 'Employee Dump', [STATUS] = "Working" ),
        FILTER (
            'Date_Table',
            [Date] <= EOMONTH ( DATE ( _year, _month, 1 ), 0 )
                && [Date] >= MIN ( 'Date_Table'[Date] )
        )
    )

 

 

 

Best Regards,

ShundaSteph

Anonymous
Not applicable

Hi @Anonymous ,

 

It is suggested to create a seperate year and month table for the slicer.

 

Anonymous
Not applicable

I appreciate it if someone helps me.

amitchandak
Super User
Super User

@Anonymous , can share the logic for MinDate and Enddate

 

Also, check if these types of formulas can help

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))

 

MTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

This Month =
var _max = eomonth(if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),0)
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Please find below for minDate & endDate logic.

minDate = calculate(min(Date_Table[Date]),ALL(Date_Table[Year],Date_Table[Month_Name]))
 
endDate = max(Date_Table[Date])

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.