The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I like to solve the following problem:
In a company some employees have worked more than 10% overtime. The task is to monitor who is consistently working overtime over the past 6 weeks and how often.
Below is some example data.
There is a time variable: last day of week, the Employee ID, the overtime done in PCT, and I worked out an OvertimeCount:
How can I showcase how many and which employee has worked overtime more than twice within a certain timeframe?
last_day_of_week | Employee ID | Overtime Pct | OTCount | OTTotal |
20/06/2021 | 12 | 2.8 | 0 | 0 |
27/06/2021 | 12 | 32.6 | 1 | 1 |
4/07/2021 | 12 | 7.6 | 0 | 0 |
11/07/2021 | 12 | 26.4 | 1 | 1 |
18/07/2021 | 12 | 20.8 | 1 | 1 |
25/07/2021 | 12 | 28.5 | 1 | 1 |
11/07/2021 | 22 | 0 | 0 | |
18/07/2021 | 22 | 0 | 0 | |
25/07/2021 | 22 | 0.0 | 0 | 0 |
1/08/2021 | 22 | 0 | 0 | |
20/06/2021 | 47 | 5.8 | 0 | 0 |
27/06/2021 | 47 | 1.3 | 0 | 0 |
4/07/2021 | 47 | 0 | 0 | |
11/07/2021 | 47 | 1.3 | 0 | 0 |
18/07/2021 | 47 | 0 | 0 | |
25/07/2021 | 47 | 0 | 0 | |
27/06/2021 | 55 | 0 | 0 | |
4/07/2021 | 55 | 5.0 | 0 | 0 |
11/07/2021 | 55 | 0 | 0 | |
18/07/2021 | 55 | 0 | 0 | |
25/07/2021 | 55 | 0 | 0 | |
20/06/2021 | 6 | 11.3 | 1 | 1 |
27/06/2021 | 6 | 0 | 0 | |
4/07/2021 | 6 | 12.5 | 1 | 1 |
11/07/2021 | 6 | 0 | 0 | |
18/07/2021 | 6 | 0 | 0 | |
25/07/2021 | 6 | 11.3 | 1 | 1 |
20/06/2021 | 35 | 0.6 | 0 | 0 |
27/06/2021 | 35 | 0.6 | 0 | 0 |
4/07/2021 | 35 | 1.9 | 0 | 0 |
11/07/2021 | 35 | 23.8 | 1 | 1 |
18/07/2021 | 35 | 2.5 | 0 | 0 |
25/07/2021 | 35 | 11.9 | 1 | 1 |
20/06/2021 | 42 | 8.8 | 0 | 0 |
27/06/2021 | 42 | 8.8 | 0 | 0 |
4/07/2021 | 42 | 6.9 | 0 | 0 |
11/07/2021 | 42 | 5.0 | 0 | 0 |
18/07/2021 | 42 | 5.0 | 0 | 0 |
25/07/2021 | 42 | 16.3 | 1 | 1 |
1/08/2021 | 42 | 6.3 | 0 | 0 |
20/06/2021 | 11 | 0 | 0 | |
27/06/2021 | 11 | 25.0 | 1 | 1 |
4/07/2021 | 11 | 0 | 0 | |
11/07/2021 | 11 | 25.0 | 1 | 1 |
18/07/2021 | 11 | 6.3 | 0 | 0 |
25/07/2021 | 11 | 25.0 | 1 | 1 |
1/08/2021 | 11 | 0 | 0 | |
20/06/2021 | 27 | 0 | 0 | |
27/06/2021 | 27 | 0 | 0 | |
4/07/2021 | 27 | 0 | 0 | |
11/07/2021 | 27 | 0 | 0 | |
18/07/2021 | 27 | 0 | 0 | |
25/07/2021 | 27 | 0 | 0 |
Solved! Go to Solution.
Hi @acg ,
Assuming there are measures (took from your previous post):
OT =
VAR currentEmpID = MAX ( T[Employee ID] )
VAR currentLDW = MAX ( T[last_day_of_week] )
VAR currentContractHours = MAX ( T[Contract_Hours] )
VAR OT =
CALCULATE (
SUM ( T[Hours] ),
FILTER (
ALL ( T[Employee ID], T[last_day_of_week] ),
T[Employee ID] = currentEmpID
&& T[last_day_of_week] = currentLDW
)
) - currentContractHours
RETURN
IF ( OT > 0, OT )
OT% =
VAR currentContractHours = MAX ( T[Contract_Hours] )
VAR OT = [OT] / currentContractHours
RETURN
OT
OT>10% = IF([OT%] >= 0.1, 1, 0)
Your OTTotal measure can be created this way:
OTTotal =
VAR _t =
ADDCOLUMNS (
SUMMARIZE ( T, T[last_day_of_week], T[Employee ID] ),
"@v", [OT>10%]
)
RETURN
SUMX ( _t, [@v] )
If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.
Check out my latest demo report in the data story gallery.
Stand with Ukraine!
Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/
Thank you!
Hi @acg ,
Assuming there are measures (took from your previous post):
OT =
VAR currentEmpID = MAX ( T[Employee ID] )
VAR currentLDW = MAX ( T[last_day_of_week] )
VAR currentContractHours = MAX ( T[Contract_Hours] )
VAR OT =
CALCULATE (
SUM ( T[Hours] ),
FILTER (
ALL ( T[Employee ID], T[last_day_of_week] ),
T[Employee ID] = currentEmpID
&& T[last_day_of_week] = currentLDW
)
) - currentContractHours
RETURN
IF ( OT > 0, OT )
OT% =
VAR currentContractHours = MAX ( T[Contract_Hours] )
VAR OT = [OT] / currentContractHours
RETURN
OT
OT>10% = IF([OT%] >= 0.1, 1, 0)
Your OTTotal measure can be created this way:
OTTotal =
VAR _t =
ADDCOLUMNS (
SUMMARIZE ( T, T[last_day_of_week], T[Employee ID] ),
"@v", [OT>10%]
)
RETURN
SUMX ( _t, [@v] )
If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.
Check out my latest demo report in the data story gallery.
Stand with Ukraine!
Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/
Thank you!
Hi ERD, strangely enough this does not work. THe measure translates fine, but I can not display it in a table. I also tried to use it in a slicer.
You are right, it is a follow up question from the previous post and OT, OT Perc and OT>10% are all measures. So the build up of the variables should not be the problem.
Any ideas why that would be? Does the
"@v"
not need to be introduced?
From what I know , I should be able to place any of the variables below into a slicer to filter on it. Would that be right, as the filter needs to be able to direct the week of choice, the ID as well as how often ID x has worked over time.
Thank you for your help.
SUMMARIZE ( T, T[last_day_of_week], T[Employee ID] ),
Should result in something like this:
Employee ID | OTTotal |
12 | 4 |
22 | 0 |
47 | 0 |
55 | 0 |
6 | 3 |
35 | 2 |
42 | 1 |
11 | 3 |
11 | 0 |
27 | 0 |
User | Count |
---|---|
12 | |
9 | |
6 | |
6 | |
6 |
User | Count |
---|---|
24 | |
14 | |
14 | |
9 | |
7 |