Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hello all,
I have an overtime data table that has 3 columns in this context:
Date (01.[Month].[Year])
EmployeeID
Overtime Hours
I want to visualize employees that has more than 270 hours of overtime a year consecutively. The reason I want to do this in DAX is because my overtime hours column is a calculated column. It is connected to a parameter that changes the calculation of total overtime hours column based on a rule.
At the end, I provided an input and desired output example. Also I provided more info as I am new to these kind of 'complicated' logics and more info means I can get better insight 🙂
Thank you all,
More info:
I have a working temporary solution in power query for now. There are 3 different calculation options. Instead of connecting these to a parameter, I referenced my main data to 3 different queries. Filtered types of overtime based on 3 different calculation options. Grouped by year, pivoted year column and then wrote a very big nested if clause that calculates the repetition amount. I have 3 bookmarks connected to 3 buttons that works like a slicer and switches between 3 identical visuals that are connected to their respective queries.
I am quite new to this kind of logics in PBI. I disliked my current solution as I had to hard code column names and there is a BIG nested if clause. Refresh time went from 5 minutes to 45 minutes.
Desired Output:
EmployeeID | Repetition Count |
1001 | 2 |
1002 | 0 |
1003 | 2 |
1004 | 3 |
Example Input for above output:
Date | EmployeeID | Overtime Hours |
1.01.2022 | 1001 | 20 |
1.02.2022 | 1001 | 19 |
1.03.2022 | 1001 | 21 |
1.04.2022 | 1001 | 17 |
1.05.2022 | 1001 | 26 |
1.06.2022 | 1001 | 27 |
1.07.2022 | 1001 | 19 |
1.08.2022 | 1001 | 23 |
1.09.2022 | 1001 | 24 |
1.10.2022 | 1001 | 28 |
1.11.2022 | 1001 | 17 |
1.12.2022 | 1001 | 23 |
1.01.2023 | 1001 | 27 |
1.02.2023 | 1001 | 24 |
1.03.2023 | 1001 | 25 |
1.04.2023 | 1001 | 26 |
1.05.2023 | 1001 | 25 |
1.06.2023 | 1001 | 26 |
1.07.2023 | 1001 | 26 |
1.08.2023 | 1001 | 22 |
1.09.2023 | 1001 | 17 |
1.10.2023 | 1001 | 24 |
1.11.2023 | 1001 | 24 |
1.12.2023 | 1001 | 18 |
1.01.2024 | 1001 | 34 |
1.02.2024 | 1001 | 34 |
1.03.2024 | 1001 | 35 |
1.04.2024 | 1001 | 38 |
1.05.2024 | 1001 | 41 |
1.06.2024 | 1001 | 27 |
1.07.2024 | 1001 | 35 |
1.08.2024 | 1001 | 36 |
1.01.2022 | 1002 | 26 |
1.02.2022 | 1002 | 21 |
1.03.2022 | 1002 | 25 |
1.04.2022 | 1002 | 17 |
1.05.2022 | 1002 | 21 |
1.06.2022 | 1002 | 28 |
1.07.2022 | 1002 | 22 |
1.08.2022 | 1002 | 18 |
1.09.2022 | 1002 | 22 |
1.10.2022 | 1002 | 18 |
1.11.2022 | 1002 | 18 |
1.12.2022 | 1002 | 28 |
1.01.2023 | 1002 | 20 |
1.02.2023 | 1002 | 22 |
1.03.2023 | 1002 | 23 |
1.04.2023 | 1002 | 21 |
1.05.2023 | 1002 | 17 |
1.06.2023 | 1002 | 20 |
1.07.2023 | 1002 | 19 |
1.08.2023 | 1002 | 28 |
1.09.2023 | 1002 | 19 |
1.10.2023 | 1002 | 27 |
1.11.2023 | 1002 | 20 |
1.12.2023 | 1002 | 19 |
1.01.2024 | 1002 | 27 |
1.02.2024 | 1002 | 37 |
1.03.2024 | 1002 | 27 |
1.04.2024 | 1002 | 26 |
1.05.2024 | 1002 | 36 |
1.06.2024 | 1002 | 27 |
1.07.2024 | 1002 | 34 |
1.08.2024 | 1002 | 31 |
1.01.2022 | 1003 | 25 |
1.02.2022 | 1003 | 19 |
1.03.2022 | 1003 | 23 |
1.04.2022 | 1003 | 23 |
1.05.2022 | 1003 | 20 |
1.06.2022 | 1003 | 17 |
1.07.2022 | 1003 | 25 |
1.08.2022 | 1003 | 24 |
1.09.2022 | 1003 | 22 |
1.10.2022 | 1003 | 18 |
1.11.2022 | 1003 | 26 |
1.12.2022 | 1003 | 26 |
1.01.2023 | 1003 | 25 |
1.02.2023 | 1003 | 21 |
1.03.2023 | 1003 | 24 |
1.04.2023 | 1003 | 27 |
1.05.2023 | 1003 | 27 |
1.06.2023 | 1003 | 19 |
1.07.2023 | 1003 | 23 |
1.08.2023 | 1003 | 19 |
1.09.2023 | 1003 | 20 |
1.10.2023 | 1003 | 26 |
1.11.2023 | 1003 | 19 |
1.12.2023 | 1003 | 27 |
1.01.2024 | 1003 | 42 |
1.02.2024 | 1003 | 42 |
1.03.2024 | 1003 | 40 |
1.04.2024 | 1003 | 27 |
1.05.2024 | 1003 | 30 |
1.06.2024 | 1003 | 30 |
1.07.2024 | 1003 | 34 |
1.08.2024 | 1003 | 41 |
1.01.2022 | 1004 | 28 |
1.02.2022 | 1004 | 18 |
1.03.2022 | 1004 | 28 |
1.04.2022 | 1004 | 25 |
1.05.2022 | 1004 | 28 |
1.06.2022 | 1004 | 22 |
1.07.2022 | 1004 | 18 |
1.08.2022 | 1004 | 22 |
1.09.2022 | 1004 | 24 |
1.10.2022 | 1004 | 25 |
1.11.2022 | 1004 | 22 |
1.12.2022 | 1004 | 18 |
1.01.2023 | 1004 | 20 |
1.02.2023 | 1004 | 19 |
1.03.2023 | 1004 | 20 |
1.04.2023 | 1004 | 21 |
1.05.2023 | 1004 | 26 |
1.06.2023 | 1004 | 24 |
1.07.2023 | 1004 | 25 |
1.08.2023 | 1004 | 24 |
1.09.2023 | 1004 | 22 |
1.10.2023 | 1004 | 26 |
1.11.2023 | 1004 | 19 |
1.12.2023 | 1004 | 25 |
1.01.2024 | 1004 | 25 |
1.02.2024 | 1004 | 34 |
1.03.2024 | 1004 | 39 |
1.04.2024 | 1004 | 34 |
1.05.2024 | 1004 | 37 |
1.06.2024 | 1004 | 37 |
1.07.2024 | 1004 | 39 |
1.08.2024 | 1004 | 37 |
Solved! Go to Solution.
Hi @merol ,
I create a table and two columns as you mentioned.
Year = YEAR('Table'[Date])
Column = IF('Table'[YearlyOvertimeHours]>270,"+","-")
Then I calculate the total result and make a new table.
YearlyOvertimeHours =
CALCULATE(
SUM('Table'[Overtime Hours]),
ALLEXCEPT('Table', 'Table'[EmployeeID], 'Table'[Year])
)
Table 2 =
SUMMARIZE (
SELECTCOLUMNS (
'Table',
"Year", 'Table'[Year],
"EmployeeID", 'Table'[EmployeeID],
"YearlyOvertimeHours", 'Table'[YearlyOvertimeHours],
"Column", 'Table'[Column]
),
[Year],
[EmployeeID],
[YearlyOvertimeHours],
[Column]
)
Next I create another two calculated columns.
Column 2 =
RANKX (
FILTER (
ALLSELECTED ( 'Table 2' ),
'Table 2'[EmployeeID] = EARLIER ( 'Table 2'[EmployeeID] )
&& 'Table 2'[Column] = "-"
),
[Year],
,
ASC
)
Column 3 =
VAR _vtable =
ADDCOLUMNS (
ALLSELECTED ( 'Table 2' ),
"_Count",
COUNTROWS (
FILTER (
ALLSELECTED ( 'Table 2' ),
'Table 2'[EmployeeID] = EARLIER ( 'Table 2'[EmployeeID] )
&& 'Table 2'[Column 2] = EARLIER ( 'Table 2'[Column 2] )
&& 'Table 2'[Column] = "+"
)
) - 1
)
VAR _vtable2 =
SELECTCOLUMNS (
FILTER (
SUMMARIZE (
_vtable,
'Table 2'[EmployeeID],
'Table 2'[Column],
"_MaxYear", MAX ( 'Table 2'[Year] ),
"_maxx",
MAXX (
FILTER ( _vtable, 'Table 2'[EmployeeID] = EARLIER ( 'Table 2'[EmployeeID] ) ),
[_Count]
)
),
'Table 2'[Column] = "+"
),
"_ID", 'Table 2'[EmployeeID],
"_outcome", [_maxx]
)
RETURN
COUNTROWS (
FILTER (
SELECTCOLUMNS (
FILTER (
SUMMARIZE (
'Table 2',
'Table 2'[EmployeeID],
'Table 2'[Column],
"_MaxYear", MAX ( 'Table 2'[Year] )
),
'Table 2'[Column] = "+"
),
"_ID", [EmployeeID],
"_Year", [_MaxYear]
),
[_ID] = 'Table 2'[EmployeeID]
)
)
+ MAXX ( FILTER ( _vtable2, [_ID] = 'Table 2'[EmployeeID] ), [_outcome] )
Finally you can get what you want.
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Please define what you mean by "Repetition" - do you mean overage in consecutive years? If yes then please provide better sample data with gaps. If no then you can use the measure below.
Hello lbendlin,
Thank you for pointing that one out. Yes, say, if someone did 270+ from 2020 to 2023 but then they were 270- in 2024, Count value I am looking for is 0.
Here is a better example output and input:
1001 | 2 |
1002 | 1 |
1003 | 2 |
1004 | 4 |
Date | EmployeeID | Overtime Hours |
1.01.2022 | 1001 | 20 |
1.02.2022 | 1001 | 19 |
1.03.2022 | 1001 | 21 |
1.04.2022 | 1001 | 17 |
1.05.2022 | 1001 | 26 |
1.06.2022 | 1001 | 27 |
1.07.2022 | 1001 | 19 |
1.08.2022 | 1001 | 23 |
1.09.2022 | 1001 | 24 |
1.10.2022 | 1001 | 28 |
1.11.2022 | 1001 | 17 |
1.12.2022 | 1001 | 23 |
1.01.2023 | 1001 | 27 |
1.02.2023 | 1001 | 24 |
1.03.2023 | 1001 | 25 |
1.04.2023 | 1001 | 26 |
1.05.2023 | 1001 | 25 |
1.06.2023 | 1001 | 26 |
1.07.2023 | 1001 | 26 |
1.08.2023 | 1001 | 22 |
1.09.2023 | 1001 | 17 |
1.10.2023 | 1001 | 24 |
1.11.2023 | 1001 | 24 |
1.12.2023 | 1001 | 18 |
1.01.2024 | 1001 | 34 |
1.02.2024 | 1001 | 34 |
1.03.2024 | 1001 | 35 |
1.04.2024 | 1001 | 38 |
1.05.2024 | 1001 | 41 |
1.06.2024 | 1001 | 27 |
1.07.2024 | 1001 | 35 |
1.08.2024 | 1001 | 36 |
1.01.2022 | 1002 | 26 |
1.02.2022 | 1002 | 21 |
1.03.2022 | 1002 | 25 |
1.04.2022 | 1002 | 17 |
1.05.2022 | 1002 | 21 |
1.06.2022 | 1002 | 28 |
1.07.2022 | 1002 | 22 |
1.08.2022 | 1002 | 18 |
1.09.2022 | 1002 | 22 |
1.10.2022 | 1002 | 18 |
1.11.2022 | 1002 | 18 |
1.12.2022 | 1002 | 28 |
1.01.2023 | 1002 | 20 |
1.02.2023 | 1002 | 22 |
1.03.2023 | 1002 | 23 |
1.04.2023 | 1002 | 21 |
1.05.2023 | 1002 | 17 |
1.06.2023 | 1002 | 20 |
1.07.2023 | 1002 | 19 |
1.08.2023 | 1002 | 28 |
1.09.2023 | 1002 | 19 |
1.10.2023 | 1002 | 27 |
1.11.2023 | 1002 | 20 |
1.12.2023 | 1002 | 19 |
1.01.2024 | 1002 | 35 |
1.02.2024 | 1002 | 37 |
1.03.2024 | 1002 | 35 |
1.04.2024 | 1002 | 26 |
1.05.2024 | 1002 | 36 |
1.06.2024 | 1002 | 35 |
1.07.2024 | 1002 | 34 |
1.08.2024 | 1002 | 34 |
1.01.2022 | 1003 | 25 |
1.02.2022 | 1003 | 19 |
1.03.2022 | 1003 | 23 |
1.04.2022 | 1003 | 23 |
1.05.2022 | 1003 | 20 |
1.06.2022 | 1003 | 17 |
1.07.2022 | 1003 | 25 |
1.08.2022 | 1003 | 24 |
1.09.2022 | 1003 | 22 |
1.10.2022 | 1003 | 18 |
1.11.2022 | 1003 | 26 |
1.12.2022 | 1003 | 26 |
1.01.2023 | 1003 | 25 |
1.02.2023 | 1003 | 21 |
1.03.2023 | 1003 | 24 |
1.04.2023 | 1003 | 27 |
1.05.2023 | 1003 | 27 |
1.06.2023 | 1003 | 19 |
1.07.2023 | 1003 | 23 |
1.08.2023 | 1003 | 19 |
1.09.2023 | 1003 | 20 |
1.10.2023 | 1003 | 26 |
1.11.2023 | 1003 | 19 |
1.12.2023 | 1003 | 27 |
1.01.2024 | 1003 | 42 |
1.02.2024 | 1003 | 42 |
1.03.2024 | 1003 | 40 |
1.04.2024 | 1003 | 27 |
1.05.2024 | 1003 | 30 |
1.06.2024 | 1003 | 30 |
1.07.2024 | 1003 | 34 |
1.08.2024 | 1003 | 41 |
1.01.2022 | 1004 | 28 |
1.02.2022 | 1004 | 18 |
1.03.2022 | 1004 | 28 |
1.04.2022 | 1004 | 25 |
1.05.2022 | 1004 | 28 |
1.06.2022 | 1004 | 22 |
1.07.2022 | 1004 | 18 |
1.08.2022 | 1004 | 22 |
1.09.2022 | 1004 | 24 |
1.10.2022 | 1004 | 25 |
1.11.2022 | 1004 | 22 |
1.12.2022 | 1004 | 18 |
1.01.2023 | 1004 | 20 |
1.02.2023 | 1004 | 19 |
1.03.2023 | 1004 | 20 |
1.04.2023 | 1004 | 21 |
1.05.2023 | 1004 | 26 |
1.06.2023 | 1004 | 24 |
1.07.2023 | 1004 | 25 |
1.08.2023 | 1004 | 24 |
1.09.2023 | 1004 | 22 |
1.10.2023 | 1004 | 26 |
1.11.2023 | 1004 | 19 |
1.12.2023 | 1004 | 25 |
1.01.2024 | 1004 | 25 |
1.02.2024 | 1004 | 34 |
1.03.2024 | 1004 | 39 |
1.04.2024 | 1004 | 34 |
1.05.2024 | 1004 | 37 |
1.06.2024 | 1004 | 37 |
1.07.2024 | 1004 | 39 |
1.08.2024 | 1004 | 37 |
1.01.2021 | 1001 | 20 |
1.02.2021 | 1001 | 19 |
1.03.2021 | 1001 | 21 |
1.04.2021 | 1001 | 21 |
1.05.2021 | 1001 | 26 |
1.06.2021 | 1001 | 27 |
1.07.2021 | 1001 | 23 |
1.08.2021 | 1001 | 23 |
1.09.2021 | 1001 | 24 |
1.10.2021 | 1001 | 28 |
1.11.2021 | 1001 | 17 |
1.12.2021 | 1001 | 23 |
1.01.2021 | 1002 | 27 |
1.02.2021 | 1002 | 24 |
1.03.2021 | 1002 | 25 |
1.04.2021 | 1002 | 26 |
1.05.2021 | 1002 | 25 |
1.06.2021 | 1002 | 26 |
1.07.2021 | 1002 | 26 |
1.08.2021 | 1002 | 22 |
1.09.2021 | 1002 | 17 |
1.10.2021 | 1002 | 24 |
1.11.2021 | 1002 | 24 |
1.12.2021 | 1002 | 18 |
1.01.2021 | 1003 | 20 |
1.02.2021 | 1003 | 19 |
1.03.2021 | 1003 | 21 |
1.04.2021 | 1003 | 17 |
1.05.2021 | 1003 | 26 |
1.06.2021 | 1003 | 27 |
1.07.2021 | 1003 | 19 |
1.08.2021 | 1003 | 23 |
1.09.2021 | 1003 | 24 |
1.10.2021 | 1003 | 28 |
1.11.2021 | 1003 | 17 |
1.12.2021 | 1003 | 23 |
1.01.2021 | 1004 | 27 |
1.02.2021 | 1004 | 24 |
1.03.2021 | 1004 | 25 |
1.04.2021 | 1004 | 26 |
1.05.2021 | 1004 | 25 |
1.06.2021 | 1004 | 26 |
1.07.2021 | 1004 | 26 |
1.08.2021 | 1004 | 22 |
1.09.2021 | 1004 | 17 |
1.10.2021 | 1004 | 24 |
1.11.2021 | 1004 | 24 |
1.12.2021 | 1004 | 18 |
Hi @merol ,
I create a table and two columns as you mentioned.
Year = YEAR('Table'[Date])
Column = IF('Table'[YearlyOvertimeHours]>270,"+","-")
Then I calculate the total result and make a new table.
YearlyOvertimeHours =
CALCULATE(
SUM('Table'[Overtime Hours]),
ALLEXCEPT('Table', 'Table'[EmployeeID], 'Table'[Year])
)
Table 2 =
SUMMARIZE (
SELECTCOLUMNS (
'Table',
"Year", 'Table'[Year],
"EmployeeID", 'Table'[EmployeeID],
"YearlyOvertimeHours", 'Table'[YearlyOvertimeHours],
"Column", 'Table'[Column]
),
[Year],
[EmployeeID],
[YearlyOvertimeHours],
[Column]
)
Next I create another two calculated columns.
Column 2 =
RANKX (
FILTER (
ALLSELECTED ( 'Table 2' ),
'Table 2'[EmployeeID] = EARLIER ( 'Table 2'[EmployeeID] )
&& 'Table 2'[Column] = "-"
),
[Year],
,
ASC
)
Column 3 =
VAR _vtable =
ADDCOLUMNS (
ALLSELECTED ( 'Table 2' ),
"_Count",
COUNTROWS (
FILTER (
ALLSELECTED ( 'Table 2' ),
'Table 2'[EmployeeID] = EARLIER ( 'Table 2'[EmployeeID] )
&& 'Table 2'[Column 2] = EARLIER ( 'Table 2'[Column 2] )
&& 'Table 2'[Column] = "+"
)
) - 1
)
VAR _vtable2 =
SELECTCOLUMNS (
FILTER (
SUMMARIZE (
_vtable,
'Table 2'[EmployeeID],
'Table 2'[Column],
"_MaxYear", MAX ( 'Table 2'[Year] ),
"_maxx",
MAXX (
FILTER ( _vtable, 'Table 2'[EmployeeID] = EARLIER ( 'Table 2'[EmployeeID] ) ),
[_Count]
)
),
'Table 2'[Column] = "+"
),
"_ID", 'Table 2'[EmployeeID],
"_outcome", [_maxx]
)
RETURN
COUNTROWS (
FILTER (
SELECTCOLUMNS (
FILTER (
SUMMARIZE (
'Table 2',
'Table 2'[EmployeeID],
'Table 2'[Column],
"_MaxYear", MAX ( 'Table 2'[Year] )
),
'Table 2'[Column] = "+"
),
"_ID", [EmployeeID],
"_Year", [_MaxYear]
),
[_ID] = 'Table 2'[EmployeeID]
)
)
+ MAXX ( FILTER ( _vtable2, [_ID] = 'Table 2'[EmployeeID] ), [_outcome] )
Finally you can get what you want.
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
this did it. thank you so much 🙂
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
25 | |
19 | |
18 | |
18 | |
17 |
User | Count |
---|---|
34 | |
25 | |
18 | |
16 | |
13 |