cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hnguyen76 Regular Visitor
Regular Visitor

YTD all employees

Good afternoon,

 

I have a formula to retrieving the count of employees entering the company for YTD. The formula works in most instances with the exception of a month when there's no type of employees (trans in, new hire, contractor).  How can I retrieve and show the last available count within that month even if the type of employee is blank?

 

The formula is as followed:

04_YTD_IN = 
Var MaxMonth = IF(SELECTEDVALUE('Date'[Date].[Month]) <> BLANK(), SELECTEDVALUE('Date'[Date].[MonthNo]), MAX('Date'[Date].[MonthNo]))
var MaxYear = FORMAT(MAX('Date'[Date]), "YYYY")
var c_Formula = CALCULATE(SUM(HC[Core HC]), HC[EMP_IN] <> BLANK(), ALL('Date'), HC[YearNum] = MaxYear, VALUE(HC[MonthNum]) <= MaxMonth)
return
c_Formula

I have a date table with a relationship to my fact table called HC that counts the number of employees coming in from column EMP_IN. 

 

In the image below, the count is 49 for April but I'm only seeing a total of 42.

YTD_IN_APR.PNG

 

In the next image below, the count is 69 for May and it's populated correctly when all the fields are present.

YTD_IN_MAY.PNG

 

So, the question is, how do I get 7 New Contractors from March to appear in April when it's blank? Thanks for the help!!!

1 ACCEPTED SOLUTION

Accepted Solutions
hnguyen76 Regular Visitor
Regular Visitor

Re: YTD all employees

Sorry for the late reply,

 

Realizing that the default YTD and custom YTD does not return all cumulative data within the date range I learned that switching over to DATESBETWEEN and ALL did the trick. For those wondering on the solution I came up with, here it is:

 

04_YTD_IN = 
var MaxYear = MAX(HC[YearNum])
var end_Date = DATEVALUE(SELECTEDVALUE('Date'[Date].[MonthNo]) & "/1/" & MAX('Date'[Date].[Year]))
var MinDate = CALCULATE(FIRSTDATE('Date'[Date]), ALL('Date'), HC[YearNum] = MaxYear)
return
CALCULATE(SUM(HC[Core HC]), FILTER(ALL(HC[EMP_IN]), HC[EMP_IN] <> BLANK()), ALL('Date'), DATESBETWEEN('Date'[Date], MinDate, end_Date))

View solution in original post

2 REPLIES 2
CheenuSing Super Contributor
Super Contributor

Re: YTD all employees

Hi @hnguyen76

 

Can you please share some data or pbix file to explore a solution.

 

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
hnguyen76 Regular Visitor
Regular Visitor

Re: YTD all employees

Sorry for the late reply,

 

Realizing that the default YTD and custom YTD does not return all cumulative data within the date range I learned that switching over to DATESBETWEEN and ALL did the trick. For those wondering on the solution I came up with, here it is:

 

04_YTD_IN = 
var MaxYear = MAX(HC[YearNum])
var end_Date = DATEVALUE(SELECTEDVALUE('Date'[Date].[MonthNo]) & "/1/" & MAX('Date'[Date].[Year]))
var MinDate = CALCULATE(FIRSTDATE('Date'[Date]), ALL('Date'), HC[YearNum] = MaxYear)
return
CALCULATE(SUM(HC[Core HC]), FILTER(ALL(HC[EMP_IN]), HC[EMP_IN] <> BLANK()), ALL('Date'), DATESBETWEEN('Date'[Date], MinDate, end_Date))

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 48 members 902 guests
Please welcome our newest community members: