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
SBSTAE
Frequent Visitor

Group by employeeid, sum and filter by single date which falls between startdate and enddate

Hi,

 

I'm trying to create a measure that sums the parttime percentages [ptfactor] of employees (grouped by) that were valid on a single selected date [selecteddate] (between [validfrom] and [validuntil]). 

 

RosterTable

idemployeeidrosteridptfactorvalidfromvaliduntil
14007211.000001-01-1131-12-11
240072780.777801-01-1202-11-14
340072980.888903-11-1431-12-14
440072980.777801-01-1530-08-15
5400723230.777831-08-1528-02-17
6400724060.777801-03-1728-02-18
7400724750.777801-03-1831-08-20
840101720.722201-01-1110-06-12
9401011640.722211-06-1204-01-15
10401012850.777805-01-1501-01-40
117020691.000001-01-1101-01-40
1280308760.777801-01-1113-05-12
13803081580.777814-05-1231-08-13
1480308760.777801-09-1331-08-14
15803082440.777801-09-1431-05-15
16803083080.777801-06-1521-06-15
17803083130.777822-06-1530-06-17
18803084250.888901-07-1721-01-18
19803084630.888922-01-1801-01-40
2014060121.000001-01-1131-12-11
2114060131.000001-01-1231-08-14
2214060171.000001-09-1401-01-40
2315015981.000001-01-1112-06-16
241501593761.000013-06-1631-08-18
251501594801.000001-09-1801-01-40

 

I'm struggling with this the last couple of days. Does someone know how I can accomplish the above? Much appreciated!

 

1 ACCEPTED SOLUTION

Thanks for that.  I noted that there was no overlap per employee.

You could create a disconnected Date table with CALENDARAUTO.

Create a slicer with this Date table.

Create a measure like this

Measure = VAR _selDate = SELECTEDVALUE(Dates[Date])
RETURN 
    CALCULATE(SUM('Table'[ptfactor]), FILTER('Table',_selDate >= 'Table'[validfrom] && _selDate < 'Table'[validuntil]))

and you could put the measure on a card OR if you want to see the employeeid results too, put the employeeid and measure in a table visual

View solution in original post

9 REPLIES 9
Icey
Community Support
Community Support

Hi @SBSTAE ,

 

Is this problem solved?

 

Best Regards,

Icey

HotChilli
Super User
Super User

Can you explain what this part means 'Group by employeeid', please.

Perhaps it would be best if you show the expected output from selecting a date e.g. 30 April 2012.

 

Thanks for the data by the way.  Many people don't post it.

@HotChilli 

 

Thank you for your reply. Group by means that per employeeid only one ptfactor will be included in the sum of all ptfactor that meet the selected date. Because the start- and enddate don't overlap the group by employeeid is probably not necessary. 

 

RosterTable

idemployeeidrosteridptfactorvalidfromvaliduntil
14007211.000001-01-1131-12-11
240072780.777801-01-1202-11-14
340072980.888903-11-1431-12-14
440072980.777801-01-1530-08-15
5400723230.777831-08-1528-02-17
6400724060.777801-03-1728-02-18
7400724750.777801-03-1831-08-20
840101720.722201-01-1110-06-12
9401011640.722211-06-1204-01-15
10401012850.777805-01-1501-01-40
117020691.000001-01-1101-01-40
1280308760.777801-01-1113-05-12
13803081580.777814-05-1231-08-13
1480308760.777801-09-1331-08-14
15803082440.777801-09-1431-05-15
16803083080.777801-06-1521-06-15
17803083130.777822-06-1530-06-17
18803084250.888901-07-1721-01-18
19803084630.888922-01-1801-01-40
2014060121.000001-01-1131-12-11
2114060131.000001-01-1231-08-14
2214060171.000001-09-1401-01-40
2315015981.000001-01-1112-06-16
241501593761.000013-06-1631-08-18
251501594801.000001-09-1801-01-40

 

Selecting april 30th 2012 will sum the purple ptfactor's totalling 5.2778‬. 

Thanks for that.  I noted that there was no overlap per employee.

You could create a disconnected Date table with CALENDARAUTO.

Create a slicer with this Date table.

Create a measure like this

Measure = VAR _selDate = SELECTEDVALUE(Dates[Date])
RETURN 
    CALCULATE(SUM('Table'[ptfactor]), FILTER('Table',_selDate >= 'Table'[validfrom] && _selDate < 'Table'[validuntil]))

and you could put the measure on a card OR if you want to see the employeeid results too, put the employeeid and measure in a table visual

@HotChilli 

I'm getting blank value as a result.

It does work when I use:

FTE =
VAR _selectedDate = SELECTEDVALUE ('DatumTabel'[Date])
RETURN CALCULATE (  SUM ( dashHrRosters[ptfactor] );    dashHrRosters[validfrom] <= _selectedDate;  dashHrRosters[validuntil] >= _selectedDate)
 
The problem was that my date table was linked in the datamodel. I didn't know that just unlinking it was the solution. 

How can I for example add another filter than just the date filter? An example: I have a another table with employmenttypes with an [employeeid, employment type, validfrom, validuntil]
 
Can I add a filter that only includes employmenttypes of a certain kind in the calculation of ptfactor? I thought of adding a calculated column to the rosters table but I read that I should avoid using calculated columns if the same can be accomplished with a measure. 

There's nothing wrong with adding a calculated column to the rosters table. If the validfrom and validuntil are the same in the employmenttypes tables as the rosters table  then it probably makes sense.  If they are the same then you will probably want to reshape your tables a bit so that you are not holding the same data in different tables.

@HotChilli 

 

Thank you. The validfrom and validuntil are different in the other table, much longer periods. Does this change the possibility to use a calculated column? 

SBSTAE
Frequent Visitor

In case someone had the same issue of filtering different tables and joining these for a measure.
I have two tables, one with employmenttypes (in a certain period) and one with rosters (what parttime percentage does an employee work in a certain period). I needed to calculate the total parttime percentage of all internal employees (internal employees are those with emptype 101 or 111) on a specific date.

 

Personeelsnummer = employeeid

The following worked for me:

 

FTE3 =
VAR _selDate = SELECTEDVALUE ('DatumTabel'[Date])
RETURN
CALCULATE(SUM(dashHrRosters[ptfactor]);
FILTER (
CROSSJOIN (
ALL ( dashHrEmploymenttypes );
ALL ( dashHrRosters )
);
(dashHrEmploymenttypes[emptype] = 101 || dashHrEmploymenttypes[emptype] = 111) && dashHrRosters[personeelsnummer] = dashHrEmploymenttypes[personeelsnummer] && dashHrRosters[validfrom] <= _selDate && dashHrRosters[validuntil] >= _selDate && dashHrEmploymenttypes[validfrom] <= _selDate && dashHrEmploymenttypes[validuntil] >= _selDate
)
)

Excellent stuff.  You took what I wrote and improved it for your more specialised case.  Well done.

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.