Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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...
User | Count |
---|---|
16 | |
15 | |
14 | |
12 | |
11 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
9 |