Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello everyone,
I am trying to calculate the total hours and months between service gaps for each employee. I am creating a list of employees who qualify for a benefit. I thought identifying the last gap to reset the count of months and hours was enough, but I realized an employee qualifies if they meet the rules even if they have a gap in service later.
Could you guys help me out?
Solved! Go to Solution.
Thanks for the reply from@lbendlin ,please allow me to provide another insight:
Regarding the issue you raised, my solution is as follows:
1.First I have created the following table and the column names and data are the data you have given:
2.Create calculated column references:
predate =
VAR currentdate = 'kk'[date]
RETURN
IF (
'kk'[gap] = "gap",
MAXX (
FILTER (
'kk',
'kk'[gap] = "gap"
&& 'kk'[date] < currentdate
&& 'kk'[id] = EARLIER ( kk[id] )
),
'kk'[date]
),
BLANK ()
)diffhour = DATEDIFF('kk'[predate],'kk'[date].[Date],HOUR)diffmonth = DATEDIFF('kk'[predate],'kk'[date].[Date],MONTH)
3.Here's my final result, which I hope meets your requirements.
4.Here is the relevant documentation:
DATEDIFF function (DAX) - DAX | Microsoft Learn
Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
Please find the attached pbix relevant to the case.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the reply from@lbendlin ,please allow me to provide another insight:
Regarding the issue you raised, my solution is as follows:
1.First I have created the following table and the column names and data are the data you have given:
2.Create calculated column references:
predate =
VAR currentdate = 'kk'[date]
RETURN
IF (
'kk'[gap] = "gap",
MAXX (
FILTER (
'kk',
'kk'[gap] = "gap"
&& 'kk'[date] < currentdate
&& 'kk'[id] = EARLIER ( kk[id] )
),
'kk'[date]
),
BLANK ()
)diffhour = DATEDIFF('kk'[predate],'kk'[date].[Date],HOUR)diffmonth = DATEDIFF('kk'[predate],'kk'[date].[Date],MONTH)
3.Here's my final result, which I hope meets your requirements.
4.Here is the relevant documentation:
DATEDIFF function (DAX) - DAX | Microsoft Learn
Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
Please find the attached pbix relevant to the case.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 19 | |
| 11 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 35 | |
| 32 | |
| 20 | |
| 12 | |
| 10 |