cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

Post Patron

Hi all,

I am trying to calculate previous months headcount. I have the below to calculate the headcount per month

var selectedDate = MAX('Date'[Date])
RETURN

I am looking for previous months headcount from the month year chosen from the slicer. If i select Oct2020, i will need to dsiplay Sept2020 headcount

Thanks

Yasir
1 ACCEPTED SOLUTION
Community Support

Hi, @yaman123

According to your description, if you have month and year column in date table, you can try like this:

``````Headcount =
VAR year =
SELECTEDVALUE ( 'Date'[year] )
VAR month =
SELECTEDVALUE ( 'Date'[month] )
VAR date =
DATE ( year, month, 1 )
VAR previousfirstday =
EDATE ( date, -1 )
VAR previouslastday =
EOMONTH ( date, -1 )
RETURN
CALCULATE (
DISTINCTCOUNT ( 'Headcount by Function'[EMP_NO] ),
|| ISBLANK ( 'Headcount by Function'[VALID_TO] ),
)``````

Best Regards

Janey Guo

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 REPLIES 4
Community Support

Hi, @yaman123

According to your description, if you have month and year column in date table, you can try like this:

``````Headcount =
VAR year =
SELECTEDVALUE ( 'Date'[year] )
VAR month =
SELECTEDVALUE ( 'Date'[month] )
VAR date =
DATE ( year, month, 1 )
VAR previousfirstday =
EDATE ( date, -1 )
VAR previouslastday =
EOMONTH ( date, -1 )
RETURN
CALCULATE (
DISTINCTCOUNT ( 'Headcount by Function'[EMP_NO] ),
|| ISBLANK ( 'Headcount by Function'[VALID_TO] ),
)``````

Best Regards

Janey Guo

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Champion

Can you try the following formula.

``Previous Month Count = CALCULATE(DISTINCTCOUNT('Headcount by Function'[EMP_NO]),DATESMTD(DATEADD('Date'[Date],-1,MONTH)))``

OR

``Previous Month Count = CALCULATE(DISTINCTCOUNT('Headcount by Function'[EMP_NO]) PREVIOUSMONTH('Date'[Date]))``

Post Patron

This doesnt work unfortunately. It brings back all employees even those who have left. I only need to show employees who were with the business last month

Community Champion

Do you want selecteddate to be the last date (31/01/2021) of previous month?

If this is the case then try the following formula:

var selectedDate = EOMONTH(TODAY(),-1)
RETURN

Announcements

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Power BI Monthly Update - February 2024

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

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors