pinarello
Member
- Joined
- Jun 21, 2019
- Messages
- 218
- Reaction score
- 4
- Points
- 18
- Location
- Germany
- Excel Version(s)
- Office 365
A standard function for calculating the net working days does not yet exist in Power Query. But since almost everyone can google meanwhile, the searcher will find what he is looking for very quickly. The enclosed folder also contains some references.
Of course, a list of non-working days can be assigned to the respective solutions in order to exclude holidays and other non-working days from the calculation.
However, I did not find a solution where it was possible to assign any number of lists with different non-working days. Furthermore, I did not like in the solutions found that lists of the individual days are generated from the respective date ranges in order to then exclude the weekends and the days off from these, even though the lists are always generated for only one data record, since the calculation of the net working days takes place in a function.
So I thought that it should be quite easy to calculate the working days without excluding the days off. And in fact this is quite simple. First the number of total days is determined and from this the number of full weeks multiplied by 2 is subtracted. Depending on the weekday start and weekday end, only 1, 2 or no day must be subtracted and we have the number of gross working days.
The next step is a table join with the holiday list with the key fields year and list name. After expanding the holidays, the next step is to insert a "1" in a new column if the holiday is within the respective period and then group the list again according to the original key and thereby determine the sum of the holidays.
The sum of the non-working days holidays is then still subtracted from the gross working days.
With regard to the runtime, periods spanning more than one year are divided beforehand among the years in question, and the list of days off is given the year as a key.
The net working days are calculated in the PQ once with internal auxiliary columns and once without auxiliary columns (column: Net wk days 1s).
In order to be able to check the results, the sample folder also contains a formula solution.
Of course, a list of non-working days can be assigned to the respective solutions in order to exclude holidays and other non-working days from the calculation.
However, I did not find a solution where it was possible to assign any number of lists with different non-working days. Furthermore, I did not like in the solutions found that lists of the individual days are generated from the respective date ranges in order to then exclude the weekends and the days off from these, even though the lists are always generated for only one data record, since the calculation of the net working days takes place in a function.
So I thought that it should be quite easy to calculate the working days without excluding the days off. And in fact this is quite simple. First the number of total days is determined and from this the number of full weeks multiplied by 2 is subtracted. Depending on the weekday start and weekday end, only 1, 2 or no day must be subtracted and we have the number of gross working days.
The next step is a table join with the holiday list with the key fields year and list name. After expanding the holidays, the next step is to insert a "1" in a new column if the holiday is within the respective period and then group the list again according to the original key and thereby determine the sum of the holidays.
The sum of the non-working days holidays is then still subtracted from the gross working days.
With regard to the runtime, periods spanning more than one year are divided beforehand among the years in question, and the list of days off is given the year as a key.
The net working days are calculated in the PQ once with internal auxiliary columns and once without auxiliary columns (column: Net wk days 1s).
In order to be able to check the results, the sample folder also contains a formula solution.
Attachments
Last edited: