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
Anonymous
Not applicable

Need help with DAX Measure Average Over-time

Hello, I need help with this measure as I'm running into some issues. 

 

I have the following: 

  1. Dates Table 
  2. Active Employee Table [With Hire Date] 
  3. InActive Employee Table [With Hire Date] 

 

I'm trying to write a dax that'll give me an average headcount in a given month. Any ideas how I can accomplish this? 

I'm attaching some screenshots for you to look at how the tables are configured. 

 

Both the Inactive and Ative tables are connected to the date table, using the Hire Date variable. 

 

Active Table 

Active Employee Table.PNG

 

InActive Table

InActive Employee Table.PNG

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Calculate these two like these and add up. Assuming the Hire date is date table. I Assume the common date table here

Active Current Employee = CALCULATE(Count(Active[EE ID]), filter(all('Date'), 'Date'[Date]<=max('Date'[Date]))
Inactive Current Employees = CALCULATE(COUNTx(FILTER(Inactive,Inactive[Hire Date]<=max('Date'[Date]) && (Inactive[Termination Date]>max('Date'[Date])))
					,(Inactive[Inactive Id ])),CROSSFILTER(Inactive[Hire Date],'Date'[Date],None))

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

Calculate these two like these and add up. Assuming the Hire date is date table. I Assume the common date table here

Active Current Employee = CALCULATE(Count(Active[EE ID]), filter(all('Date'), 'Date'[Date]<=max('Date'[Date]))
Inactive Current Employees = CALCULATE(COUNTx(FILTER(Inactive,Inactive[Hire Date]<=max('Date'[Date]) && (Inactive[Termination Date]>max('Date'[Date])))
					,(Inactive[Inactive Id ])),CROSSFILTER(Inactive[Hire Date],'Date'[Date],None))
Anonymous
Not applicable

@amitchandak  This is producing excatly what I want! is there a way for us to exclude calculations on future dates with that dax? I noticed that based on the end date of my dates table, it's repeating the current number over and over and over and over. 

Put a visual or page level filter on the date table show <= today using relative or advance option. We can also add today to calculation as an additional filter <= today(), but it might not work in few cases.

Anonymous
Not applicable

That worked like a charm!!! Accpeting this as a solution. Thank You Much!! really apprecaite it. 

amitchandak
Super User
Super User

Please refer to the solution in blog. As you have two tables you have to do some changes.

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

Anonymous
Not applicable

@amitchandak  thanks for that! It was helpful in other ways, but not for what I'm trying to achieve. 

@JarroVGIT  I appreciate your feedback!

 

As to your question, could you elaborate a bit on the two tables?

 

By the name I would expect only active employees in the 'Active' table? Yes, this is correct

Or is the first table actually all hire dates and is the second table all termination dates? No, first table is all active and second table is all inactive 

In that case, does that mean that for every row in the Active table, the EE ID is unique?  (and the same for InActive table?) Yes, EE ID is unique in both tables

 

 

JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

Just an fyi: posting tables as pictures makes it incredibly (and unnessarely) hard for us to reproduce your usecase. Please consider posting copy-ready tables or attach an Excel/PBIX file via a cloud service as OneDrive or Dropbox.

As to your question, could you elaborate a bit on the two tables? By the name I would expect only active employees in the 'Active' table? Or is the first table actually all hire dates and is the second table all termination dates? In that case, does that mean that for every row in the Active table, the EE ID is unique?  (and the same for InActive table?)





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.