Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Determining EmployeeIDs with value sums above threshold X years in a row

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:

 

EmployeeIDRepetition Count
10012
10020
10032
10043

 

Example Input for above output:

 

DateEmployeeIDOvertime Hours
1.01.2022100120
1.02.2022100119
1.03.2022100121
1.04.2022100117
1.05.2022100126
1.06.2022100127
1.07.2022100119
1.08.2022100123
1.09.2022100124
1.10.2022100128
1.11.2022100117
1.12.2022100123
1.01.2023100127
1.02.2023100124
1.03.2023100125
1.04.2023100126
1.05.2023100125
1.06.2023100126
1.07.2023100126
1.08.2023100122
1.09.2023100117
1.10.2023100124
1.11.2023100124
1.12.2023100118
1.01.2024100134
1.02.2024100134
1.03.2024100135
1.04.2024100138
1.05.2024100141
1.06.2024100127
1.07.2024100135
1.08.2024100136
1.01.2022100226
1.02.2022100221
1.03.2022100225
1.04.2022100217
1.05.2022100221
1.06.2022100228
1.07.2022100222
1.08.2022100218
1.09.2022100222
1.10.2022100218
1.11.2022100218
1.12.2022100228
1.01.2023100220
1.02.2023100222
1.03.2023100223
1.04.2023100221
1.05.2023100217
1.06.2023100220
1.07.2023100219
1.08.2023100228
1.09.2023100219
1.10.2023100227
1.11.2023100220
1.12.2023100219
1.01.2024100227
1.02.2024100237
1.03.2024100227
1.04.2024100226
1.05.2024100236
1.06.2024100227
1.07.2024100234
1.08.2024100231
1.01.2022100325
1.02.2022100319
1.03.2022100323
1.04.2022100323
1.05.2022100320
1.06.2022100317
1.07.2022100325
1.08.2022100324
1.09.2022100322
1.10.2022100318
1.11.2022100326
1.12.2022100326
1.01.2023100325
1.02.2023100321
1.03.2023100324
1.04.2023100327
1.05.2023100327
1.06.2023100319
1.07.2023100323
1.08.2023100319
1.09.2023100320
1.10.2023100326
1.11.2023100319
1.12.2023100327
1.01.2024100342
1.02.2024100342
1.03.2024100340
1.04.2024100327
1.05.2024100330
1.06.2024100330
1.07.2024100334
1.08.2024100341
1.01.2022100428
1.02.2022100418
1.03.2022100428
1.04.2022100425
1.05.2022100428
1.06.2022100422
1.07.2022100418
1.08.2022100422
1.09.2022100424
1.10.2022100425
1.11.2022100422
1.12.2022100418
1.01.2023100420
1.02.2023100419
1.03.2023100420
1.04.2023100421
1.05.2023100426
1.06.2023100424
1.07.2023100425
1.08.2023100424
1.09.2023100422
1.10.2023100426
1.11.2023100419
1.12.2023100425
1.01.2024100425
1.02.2024100434
1.03.2024100439
1.04.2024100434
1.05.2024100437
1.06.2024100437
1.07.2024100439
1.08.2024100437
1 ACCEPTED SOLUTION

Hi @Anonymous ,

I create a table and two columns as you mentioned.

Year = YEAR('Table'[Date])

vyilongmsft_0-1726038456630.png

Column = IF('Table'[YearlyOvertimeHours]>270,"+","-")

vyilongmsft_1-1726038508211.png

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]
)

vyilongmsft_3-1726038859891.png

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.

vyilongmsft_4-1726040549708.png

 

 

 

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.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

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.

 

lbendlin_1-1725654950144.png

 

 

Anonymous
Not applicable

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:

 

10012
10021
10032
10044

 

DateEmployeeIDOvertime Hours
1.01.2022100120
1.02.2022100119
1.03.2022100121
1.04.2022100117
1.05.2022100126
1.06.2022100127
1.07.2022100119
1.08.2022100123
1.09.2022100124
1.10.2022100128
1.11.2022100117
1.12.2022100123
1.01.2023100127
1.02.2023100124
1.03.2023100125
1.04.2023100126
1.05.2023100125
1.06.2023100126
1.07.2023100126
1.08.2023100122
1.09.2023100117
1.10.2023100124
1.11.2023100124
1.12.2023100118
1.01.2024100134
1.02.2024100134
1.03.2024100135
1.04.2024100138
1.05.2024100141
1.06.2024100127
1.07.2024100135
1.08.2024100136
1.01.2022100226
1.02.2022100221
1.03.2022100225
1.04.2022100217
1.05.2022100221
1.06.2022100228
1.07.2022100222
1.08.2022100218
1.09.2022100222
1.10.2022100218
1.11.2022100218
1.12.2022100228
1.01.2023100220
1.02.2023100222
1.03.2023100223
1.04.2023100221
1.05.2023100217
1.06.2023100220
1.07.2023100219
1.08.2023100228
1.09.2023100219
1.10.2023100227
1.11.2023100220
1.12.2023100219
1.01.2024100235
1.02.2024100237
1.03.2024100235
1.04.2024100226
1.05.2024100236
1.06.2024100235
1.07.2024100234
1.08.2024100234
1.01.2022100325
1.02.2022100319
1.03.2022100323
1.04.2022100323
1.05.2022100320
1.06.2022100317
1.07.2022100325
1.08.2022100324
1.09.2022100322
1.10.2022100318
1.11.2022100326
1.12.2022100326
1.01.2023100325
1.02.2023100321
1.03.2023100324
1.04.2023100327
1.05.2023100327
1.06.2023100319
1.07.2023100323
1.08.2023100319
1.09.2023100320
1.10.2023100326
1.11.2023100319
1.12.2023100327
1.01.2024100342
1.02.2024100342
1.03.2024100340
1.04.2024100327
1.05.2024100330
1.06.2024100330
1.07.2024100334
1.08.2024100341
1.01.2022100428
1.02.2022100418
1.03.2022100428
1.04.2022100425
1.05.2022100428
1.06.2022100422
1.07.2022100418
1.08.2022100422
1.09.2022100424
1.10.2022100425
1.11.2022100422
1.12.2022100418
1.01.2023100420
1.02.2023100419
1.03.2023100420
1.04.2023100421
1.05.2023100426
1.06.2023100424
1.07.2023100425
1.08.2023100424
1.09.2023100422
1.10.2023100426
1.11.2023100419
1.12.2023100425
1.01.2024100425
1.02.2024100434
1.03.2024100439
1.04.2024100434
1.05.2024100437
1.06.2024100437
1.07.2024100439
1.08.2024100437
1.01.2021100120
1.02.2021100119
1.03.2021100121
1.04.2021100121
1.05.2021100126
1.06.2021100127
1.07.2021100123
1.08.2021100123
1.09.2021100124
1.10.2021100128
1.11.2021100117
1.12.2021100123
1.01.2021100227
1.02.2021100224
1.03.2021100225
1.04.2021100226
1.05.2021100225
1.06.2021100226
1.07.2021100226
1.08.2021100222
1.09.2021100217
1.10.2021100224
1.11.2021100224
1.12.2021100218
1.01.2021100320
1.02.2021100319
1.03.2021100321
1.04.2021100317
1.05.2021100326
1.06.2021100327
1.07.2021100319
1.08.2021100323
1.09.2021100324
1.10.2021100328
1.11.2021100317
1.12.2021100323
1.01.2021100427
1.02.2021100424
1.03.2021100425
1.04.2021100426
1.05.2021100425
1.06.2021100426
1.07.2021100426
1.08.2021100422
1.09.2021100417
1.10.2021100424
1.11.2021100424
1.12.2021100418

Hi @Anonymous ,

I create a table and two columns as you mentioned.

Year = YEAR('Table'[Date])

vyilongmsft_0-1726038456630.png

Column = IF('Table'[YearlyOvertimeHours]>270,"+","-")

vyilongmsft_1-1726038508211.png

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]
)

vyilongmsft_3-1726038859891.png

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.

vyilongmsft_4-1726040549708.png

 

 

 

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.

Anonymous
Not applicable

this did it. thank you so much 🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.