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
BJE
Helper I
Helper I

Creating sum function in date table from conditional data in another table

I have an employee dataset that will be updated daily. The dataset contains a single row for each employee and the columns contain a range of information including title, employment basis, commencement date, termination date, standard hours, etc.

 

Using this data, I need to calculate totals based on certain characteristics for different intervals (i.e. monthly). The calculation needs to work retrospectively as well as apply to additional data going forward.

 

I have two data tables for this purpose. An example of the employee data is below:

 

EMPNOFTECOMMDATETERMDATE
1114-Jul-812-Jul-04
213-Nov-16 
3119-Sep-8822-Aug-07
411-Nov-18 
511-Nov-18 
611-Nov-18 
711-Nov-18 
811-Nov-1828-Jun-19
911-Nov-1829-May-19

 

Secondly, I have a dates table as follows:

 

YearMonthMonth Start DateMonth End DateYear YTD Start DateYear YTD End Date
2015-16Jul-151/07/201531/07/20151/07/201531/07/2015
2015-16Aug-151/08/201531/08/20151/07/201531/08/2015
2015-16Sep-151/09/201530/09/20151/07/201530/09/2015
2015-16Oct-151/10/201531/10/20151/07/201531/10/2015
2015-16Nov-151/11/201530/11/20151/07/201530/11/2015
2015-16Dec-151/12/201531/12/20151/07/201531/12/2015
2015-16Jan-161/01/201631/01/20161/07/201531/01/2016
2015-16Feb-161/02/201629/02/20161/07/201529/02/2016
2015-16Mar-161/03/201631/03/20161/07/201531/03/2016
2015-16Apr-161/04/201630/04/20161/07/201530/04/2016
2015-16May-161/05/201631/05/20161/07/201531/05/2016
2015-16Jun-161/06/201630/06/20161/07/201530/06/2016

 

I need to create a unique sum of FTE hours for all employees that were current for a given period and do this for all periods. The parameters for a given period would be that COMMDATE <= Month End Date and TERMDATE >= Month Start Date or TERMDATE is null.

 

I think this needs to be done as an additional column to my date table rather than as a measure but whatever approach I have taken has not worked. Any advice from anyone that has encountered this problem and developed a solution is welcome.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

mmhhh ... the problem could be THEN some exchange of table name, hopefully.

 

let we try to get step clear.

 

I try to use the name you showed in the screen shot of code you are using. You should control carefully to find any difference.

 

image.png

 

#"Added Custom" = Table.AddColumn(#"Changed Type", "Monthly ASL", each List.Sum(Table.SelectRows(Empshot, (f)=> f[COMMDATE] <= [Month End Date] and (f[TERMDATE] >= [Month Start Date] or f[TERMDATE] is null))[FTE])),

 

 

This means that Empshot is the table aving as columns EMPNO/FTE/COMMDATE/TERMDATE

 

#"Changed Type" is youtable at previous step.

 

PS

just as last chance check if there is some blank in one of the names.

View solution in original post

14 REPLIES 14

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.

Top Solution Authors
Top Kudoed Authors