Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Happy Friday, and thank you in advance for any assistance you can give. I currently have the measure below to count the number of employees that were active during a selected period, and I need to modify it to calculate how many months during the selected period they were active. I need this to calculate each individual employee, and then roll up through the hierarchy (Employee > Location > Market).
Each employee has a [Termination Date] and a [Hire Date]. My thought was to do a DATEDIFF to calculate this for each employee, but I'm unsure how to accomplish it, since I cannot just use the selected date range for the DATEDIFF parameters - if the employee was hired during the selected date range then their [Hire Date] should be used in place of the minimum selected date, same thing for [Termination Date] and max date.
Measure =
Solved! Go to Solution.
Hi @tarmogolf ,
Create a date slicer table and use Min() to get the range start and use Max() to get range end.
Then create a measure like below:
meaasure =
VAR _start =
IF (
SELECTEDVALUE ( 'Employee Roster'[StartDate] ) > MIN ( 'Date'[Date] ),
SELECTEDVALUE ( 'Employee Roster'[StartDate] ),
MIN ( 'Date'[Date] )
)
VAR _end =
IF (
SELECTEDVALUE ( 'Employee Roster'[TerminationDate] ) < MAX ( 'Date'[Date] ),
SELECTEDVALUE ( 'Employee Roster'[TerminationDate] ),
MAX ( 'Date'[Date] )
)
RETURN
DATEDIFF ( _start, _end, DAY )
Best Regards,
Jay
Hi @tarmogolf ,
Create a date slicer table and use Min() to get the range start and use Max() to get range end.
Then create a measure like below:
meaasure =
VAR _start =
IF (
SELECTEDVALUE ( 'Employee Roster'[StartDate] ) > MIN ( 'Date'[Date] ),
SELECTEDVALUE ( 'Employee Roster'[StartDate] ),
MIN ( 'Date'[Date] )
)
VAR _end =
IF (
SELECTEDVALUE ( 'Employee Roster'[TerminationDate] ) < MAX ( 'Date'[Date] ),
SELECTEDVALUE ( 'Employee Roster'[TerminationDate] ),
MAX ( 'Date'[Date] )
)
RETURN
DATEDIFF ( _start, _end, DAY )
Best Regards,
Jay
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
87 | |
82 | |
71 | |
49 |
User | Count |
---|---|
143 | |
120 | |
110 | |
60 | |
57 |