Forum Discussion
Rolling dates
- 7 years ago
Hi dax ,
After some real DAX struggles I found a solution, it might be not the perfect DAX, but for now it works.
I had three tables:
1. Employee table 1 - N 2, Absence table
3. Date tableAbsence Hours = VAR OutsideWeek = //time between start week ---> end week (+1 to exclude sunday) SUMX ( FILTER ( Absence; Absence[StartDate] <= FIRSTDATE ( 'Date'[Date] ) && Absence[EndDate] >= LASTDATE ( 'Date'[Date])) ; DATEDIFF ( (FIRSTDATE( 'Date'[Date] ) + 1); LASTDATE( 'Date'[Date] ); DAY ) * 8 ) VAR StartIsOutSideWeek = // time between start absence ---> end week SUMX ( FILTER ( Absence; Absence[StartDate] > FIRSTDATE ( 'Date'[Date] ) && Absence[StartDate] < LASTDATE ( 'Date'[Date] ) && Absence[EndDate] >= LASTDATE ( 'Date'[Date] )) ; DATEDIFF ( Absence[StartDate]; LASTDATE ( 'Date'[Date] ); DAY ) * 8 ) VAR EndOutsideWeek = // time between start week ---> end absence (+1 day to exclude sunday) SUMX ( FILTER ( Absence; Absence[StartDate] < FIRSTDATE ( 'Date'[Date] ) && Absence[EndDate] > FIRSTDATE( 'Date'[Date] ) && Absence[EndDate] < LASTDATE ( 'Date'[Date] ) ); DATEDIFF ( (FIRSTDATE('Date'[Date])+1); Absence[EndDate]; DAY ) * 8 ) VAR InsideWeek = // time between start absence ---> end absence SUMX ( FILTER ( Absence; Absence[StartDate] >= FIRSTDATE ( 'Date'[Date] ) && Absence[EndDate] <= LASTDATE ( 'Date'[Date] ) ); DATEDIFF ( Absence[StartDate]; Absence[EndDate]; DAY ) * 8 ) RETURN OutsideWeek + StartIsOutSideWeek + EndOutsideWeek + InsideWeek +[Open Absence Hours]Open Absence Hours = // calculates the hours for absence with end day blank() VAR StartPreviousWeek = // time between start absence in previous week ---> end week SUMX ( FILTER ( Absence; Absence[StartDate] < LASTDATE ( 'Date'[Date] ) && Absence[StartDate] > FIRSTDATE ( 'Date'[Date] ) && Absence[EndDate] = BLANK () ); DATEDIFF ( Absence[StartDate]; LASTDATE ( 'Date'[Date] ); DAY ) * 8 ) VAR StartOutsideWeek = SUMX ( FILTER ( Absence; Absence[StartDate] <= FIRSTDATE ( 'Date'[Date] ) && Absence[EndDate] = BLANK () ); DATEDIFF ( ( FIRSTDATE ( 'Date'[Date] ) + 1 ); LASTDATE ( 'Date'[Date] ); DAY ) * 8 ) RETURN StartOutsideWeek + StartPreviousWeekFor more details, you can check the file here:
https://www.dropbox.com/s/jte4onfidloiepz/Example.pbix?dl=0
Thanks,
Bwl.
Hi BWL,
I can’t reproduce your design just based on your description, so if possible , could you please inform me more detailed information (such as your sample data and your expecting output)? Then I will help you more correctly.
You could refer to How to Get Your Question Answered Quickly for details.
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi dax,
Just created at example pbix file.
Can I share it directly with you, because I don't see where I can upload it in this forum.
KInd regards.
- dax7 years agoCommunity Support
Hi BWL,
You could try to upload pbix file in onedrive or other place which we could access to .
Best Regards,
Zoe Zhi