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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dcormiernj
Helper I
Helper I

How to calculate total hours where consecutive weeks > 40 and hours are by week end date (sunday)

We are implementing a bonus type plan and part of the calculation is to skip any PTO hours that are > 40 for any two or more consecutive weeks.  I have pasted below sample data and this data comes from a BI table. I have tried all kinds of BI things such as datesin period etc.  But the hours are by week end date.  I finally gave up and put the data into excel.  the excel formula that works and gives me what i want is pasted below.  A=username, G is total PTO hours

 

=IF(A2<>A1,IF(G2+G3>40,G2,0),IF(A2<>A3,IF(G2+G1>40,G2,0),IF(OR(G2+G1>40,G2+G3>40),G2,0)))

 

This formula gives me exactly what i want in the pasted table below column "PTO-AddBack"  but i cant for the life of me figure out how to do this formula in BI.

Can anyone help?

thank you

 

 

UserNameTimesheetEndDateTotal PTO HoursQualifiedPTO-AddBack
John4/9/2023 10
John4/16/2023810
John4/23/2023410
John4/30/2023 10
John5/7/2023410
John5/14/2023810
John5/21/2023 10
John5/28/2023 10
John6/4/2023 10
John6/11/2023810
John6/18/2023 10
John6/25/2023 10
John7/2/2023 10
Mary4/9/2023 10
Mary4/16/2023 10
Mary4/23/2023 10
Mary4/30/2023 10
Mary5/7/2023 10
Mary5/14/2023 10
Mary5/21/2023 10
Mary5/28/2023 10
Mary6/4/2023 10
Mary6/11/2023 10
Mary6/18/2023 10
Mary6/25/2023 10
Mary7/2/2023 10
Alex4/9/2023 10
Alex4/16/2023 10
Alex4/23/2023 10
Alex4/30/2023 10
Alex5/7/2023 10
Alex5/14/2023 10
Alex5/21/2023 10
Alex5/28/2023 10
Alex6/4/2023 10
Alex6/11/2023 10
Alex6/18/2023 10
Alex6/25/2023 10
Alex7/2/20231210
Chris4/9/2023 10
Chris4/16/2023 10
Chris4/23/2023 10
Chris4/30/2023 10
Chris5/7/2023 10
Chris5/14/2023 10
Chris5/21/2023 10
Chris5/28/2023810
Chris6/4/2023 10
Chris6/11/2023 10
Chris6/18/2023 10
Chris6/25/2023 10
Chris7/2/2023810
Kathy4/9/2023 10
Kathy4/16/2023 10
Kathy4/23/2023 10
Kathy4/30/2023 10
Kathy5/7/2023 10
Kathy5/14/2023 10
Kathy5/21/20232010
Kathy5/28/2023 10
Kathy6/4/2023410
Kathy6/11/2023 10
Kathy6/18/2023 10
Kathy6/25/202340140
Kathy7/2/202319119
Larry4/9/2023 10
Larry4/16/2023 10
Larry4/23/2023 10
Larry4/30/2023 10
Larry5/7/2023 10
Larry5/14/2023810
Larry5/21/2023 10
Larry5/28/2023 10
Larry6/4/2023 10
Larry6/11/202340140
Larry6/18/202340140
Larry6/25/202340140
Larry7/2/202340140
2 ACCEPTED SOLUTIONS

This is Awesome!  Thank you very much.

View solution in original post

Hi @dcormiernj ,

 

Please consider about marking my reply if it helped you.
This will be able to better help people with similar problems. In addition, marking a reply that helped you also recognizes the person who helped you, which will better encourage users to respond positively.

 

Best Regards,

Jianbo Li

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

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @dcormiernj ,

 

Please try:

Column =
VAR _a =
    SUMX (
        FILTER (
            'Table',
            [UserName] = EARLIER ( 'Table'[UserName] )
                && [TimesheetEndDate]
                    = EARLIER ( 'Table'[TimesheetEndDate] ) - 7
        ),
        [Total PTO Hours]
    )
VAR _b =
    SUMX (
        FILTER (
            'Table',
            [UserName] = EARLIER ( 'Table'[UserName] )
                && [TimesheetEndDate]
                    = EARLIER ( 'Table'[TimesheetEndDate] ) + 7
        ),
        [Total PTO Hours]
    )
VAR _c =
    IF ( [Total PTO Hours] <> BLANK () && OR ( _a <> BLANK (), _b <> BLANK () ), 1 )
VAR _d =
    MAXX (
        FILTER (
            'Table',
            [UserName] = EARLIER ( 'Table'[UserName] )
                && [TimesheetEndDate] < EARLIER ( 'Table'[TimesheetEndDate] )
                && NOT (
                    [Total PTO Hours] <> BLANK ()
                        && OR ( _a <> BLANK (), _b <> BLANK () )
                )
        ),
        [TimesheetEndDate]
    )
VAR _e =
    MINX (
        FILTER (
            'Table',
            [UserName] = EARLIER ( 'Table'[UserName] )
                && [TimesheetEndDate] > EARLIER ( 'Table'[TimesheetEndDate] )
                && NOT (
                    [Total PTO Hours] <> BLANK ()
                        && OR ( _a <> BLANK (), _b <> BLANK () )
                )
        ),
        [TimesheetEndDate]
    )
VAR _f =
    IF (
        ISBLANK ( _d ),
        MINX (
            FILTER ( 'Table', [UserName] = EARLIER ( 'Table'[UserName] ) ),
            [TimesheetEndDate]
        ),
        _d + 7
    )
VAR _g =
    IF (
        ISBLANK ( _e ),
        MAXX (
            FILTER ( 'Table', [UserName] = EARLIER ( 'Table'[UserName] ) ),
            [TimesheetEndDate]
        ),
        _e - 7
    )
VAR _h =
    SUMX (
        FILTER (
            'Table',
            [UserName] = EARLIER ( 'Table'[UserName] )
                && [TimesheetEndDate] >= _f
                && [TimesheetEndDate] <= _g
        ),
        [Total PTO Hours]
    )
RETURN
    IF ( _c = 1 && _h > 40, [Total PTO Hours], 0 )

Final output:

vjianbolimsft_0-1689748959684.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This is Awesome!  Thank you very much.

Hi @dcormiernj ,

 

Please consider about marking my reply if it helped you.
This will be able to better help people with similar problems. In addition, marking a reply that helped you also recognizes the person who helped you, which will better encourage users to respond positively.

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.