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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
jackisc
New Member

Plz help with Dax

My clock in and clock out date is in rows.

Below DAX helped me subtract the break time of 45 minutes from the employees who worked 8hrs or more perday since it's mandatory. However, I wanted to edit it to include another clause where if employee who works 6hrs or less then "Do not deduct break time" but I am unable to make it work. Any suggestions on how I can achieve this with current DAX? Also, if there is better and easier way to achieve the end results please suggest that as well. Thank you!

 

Target Wrk Hrs =
VAR _a =
    SUMX ('Table1',
        IF (
         [Index] = 2,
         DATEDIFF (
                CALCULATE (
                    MAX ('Table1'[Check-in or Check-out Time] ),
                    FILTER ('Table1', [Index] = 1
                            && [Check-in or Check-out Time] < EARLIER ( 'Table1'[Check-in or Check-out Time])
                            && [Enter Reporting Date] = EARLIER ( [Enter Reporting Date] )
                    )
                ),
                [Check-in or Check-out Time],
                MINUTE
        )
        )
    )
 VAR _b=    
SUMX ('Table1',
IF (
            [Index] = 1,
            DATEDIFF (
                CALCULATE (
                    MAX ('Table1'[Check-in or Check-out Time]),
                    FILTER ('Table1',[Enter Reporting Date] = EARLIER ('Table1'[Enter Reporting Date])
                            && [Index] = 2
                            && [Check-in or Check-out Time] < EARLIER('Table1'[Check-in or Check-out Time])
                    )
                ),
                [Check-in or Check-out Time],
                MINUTE
            )
        )
    )
VAR _c=
    IF ( _b < 45, 45, 0)
VAR _d = ( _a - _c ) / 60
RETURN
    INT ( _d )
        + 0.01
            * MOD ( _a - _c, 60 )
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @jackisc ,

 

Here are the steps you can follow:

1. In Power Query -- add Column – Index Column – From 1.

vyangliumsft_0-1707209152431.jpeg

2. Create calculated column.

Date_time =
[Date]+[Time]
Test01 =
var _last=
MAXX(
    FILTER('Table',
    'Table'[Index.1]=EARLIER('Table'[Index.1])-1&&'Table'[In/Out]="In"),[Date_time])  
return
DATEDIFF(
   _last, [Date_time] , HOUR)
Test02 =
var _result=
IF(
    [Test01]=BLANK(),
MAXX(
    FILTER(ALL('Table'),'Table'[Index.1]=EARLIER('Table'[Index.1])+1&&'Table'[In/Out]="Out"),[Test01]),[Test01])
return
IF(
    _result>=8,"8hr - subtracting 45 minutes of break time","6hr - no need to subtract break time")

3. Result:

vyangliumsft_1-1707209152434.png

 

 

Best Regards,

Liu Yang

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

5 REPLIES 5
Anonymous
Not applicable

Hi  @jackisc ,

 

Here are the steps you can follow:

1. In Power Query -- add Column – Index Column – From 1.

vyangliumsft_0-1707209152431.jpeg

2. Create calculated column.

Date_time =
[Date]+[Time]
Test01 =
var _last=
MAXX(
    FILTER('Table',
    'Table'[Index.1]=EARLIER('Table'[Index.1])-1&&'Table'[In/Out]="In"),[Date_time])  
return
DATEDIFF(
   _last, [Date_time] , HOUR)
Test02 =
var _result=
IF(
    [Test01]=BLANK(),
MAXX(
    FILTER(ALL('Table'),'Table'[Index.1]=EARLIER('Table'[Index.1])+1&&'Table'[In/Out]="Out"),[Test01]),[Test01])
return
IF(
    _result>=8,"8hr - subtracting 45 minutes of break time","6hr - no need to subtract break time")

3. Result:

vyangliumsft_1-1707209152434.png

 

 

Best Regards,

Liu Yang

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

Greg_Deckler
Community Champion
Community Champion

@jackisc Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

 

Dataset sample

jackisc_0-1706891378275.png

 

 

@jackisc Thanks but can you paste that as text so I don't have to type it all?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Date Check in-out time In/Out Time Index      End Result
1/3/2024 Checking-in In 07:00:05        1                  8hr - subtracting 45 minutes of break time
1/3/2024 Checking-out Out 15:45:00   2
1/4/2024 Checking-in in 09:00:00        1                  6hr - no need to subtract break time
1/4/2024 Checking-out out 15:01:00   2
1/5/2024 Checking-in in      07:30:00   1                  8hr - subtracting 45 minutes of break time
1/5/2024 Checking-out out 16:15:00   2

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.