Forum Discussion
Adding only workdays to a specific date
- 8 years ago
Hi,
I created the calculations.
Try having a look at this: https://www.dropbox.com/s/5fareeag77bfc6x/power%20bi%20example.pbix?dl=0&m=
Result:
- 8 years ago
Okay - to assist others with similar challenges I will just make a short description of the solution I created.
First make sure that there is a relationship between the table and the calendar table.
Then in the calendar table create a few columns to create an index for workingdays
IsWorkday = SWITCH( WEEKDAY('Calendar'[Date]); 1; 0; 7; 0;1 ) WorkingDayIndex = RANKX( FILTER( 'Calendar'; 'Calendar'[IsWorkDay] = 1 ); 'Calendar'[Date]; ;ASC )Then in the table that should hold the result I created this calculation that make a simple lookup in the calendar table using the index column created above.
NewDate = VAR DateIdx = CALCULATE( MAX( 'Calendar'[WorkingDayIndex] ); 'Table1'[Date] = RELATED('Calendar'[Date] ) ) VAR NewDateIdx = DateIdx + Table1[Transport days] RETURN CALCULATE( MAX('Calendar'[Date]); FILTER( ALL('Calendar'); 'Calendar'[WorkingDayIndex] = NewDateIdx && 'Calendar'[IsWorkday] = 1 ) )
As an example to further explane what i mean
the date 02.04.2017 with 16 days transport time would need the result to be 24.04.2017 when just counting work days.
and NOT 18.04.2017 (countet with weekends)
Try adding a working days index to your period table. If a day is not a working day then assign the same index number to this day as the previous day - then you should be able to calculate a column in your table where you find the index of your initial date add the transportation days to the index and return the lowest date with that index.
- Anonymous8 years agoNot applicable
thank you for the reply
Could you give me an example on how you would write that? i am still very new to writing my own columns/measures
- sdjensen8 years agoSolution Sage
This would be much easier if you shared a base model with some date - at least the data you posted earlier (as a picture) and a period table.
But to calculate the index in your period table you could try something like this.
Column1: IsWorkingDay = IF( Period[DayOfWeekNumber] = 6 || Period[DayOfWeekNumber] = 7; 0; 1 ) Column2: WorkingDaysIndex = RANKX( FILTER( Period; Period[IsWorkingDay] = 1 ); Period[Date]; ;ASC )IsWorkingDay calculates a column that will return a 1 if the day is not a Saturday or Sunday.
WorkingDaysIndex then calculates the index based on IsWorkingDay.
I can see from my small test that the rank on a Saturday is 1 larger than on a Friday, so instead of MIN date you should find the MAX date where index is equal Index from starting date + Transportation days
- Anonymous8 years agoNot applicable
Made a quick model here for you, hope that helps.
https://www.dropbox.com/s/829noofd84yrr38/power%20bi%20example.pbix?dl=0