Forum Discussion
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!
- Anonymous2 years ago
Hi jackisc ,
Here are the steps you can follow:
1. In Power Query -- add Column – Index Column – From 1.
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:
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
5 Replies
- Greg_DecklerCommunity 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.- jackiscNew Member
Dataset sample
- Greg_DecklerCommunity Champion
jackisc Thanks but can you paste that as text so I don't have to type it all?
- AnonymousNot applicable
Hi jackisc ,
Here are the steps you can follow:
1. In Power Query -- add Column – Index Column – From 1.
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:
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