Power Query NetworkDays: Count Working Days in Excel
In this article
Power Query has no built-in NETWORKDAYS function, but you can get the same result by generating a list of dates between a start and end date, filtering out weekends, and counting the rows. The cleanest way is to add a custom column that builds the range with List.Dates, removes Saturdays and Sundays with List.Select, then wraps the result in List.Count. Excluding public holidays needs one extra step: keep a holiday table and filter it out of the same list with List.Difference.
The technique is worth learning because it works on whole columns of data in one refresh, rather than copying down a formula row by row. The example below counts business days between a Start Date and an End Date column.
What You'll Need
- A query with a column holding start dates and another holding end dates, both formatted as Date. If they are Text, change the type first using the type icon in the column header.
- A holiday table (optional) set up as a single column of dates, with a header such as HolidayDate. Any list of dates works, but a proper table is easier to maintain.
- A basic grasp of the Power Query Editor, which lives at Data > Get Data in Excel. Labels and menus can differ slightly between Excel versions and between Excel and Power BI.
Step-by-Step
- Load both tables into Power Query. Select your main table and go to Data > From Table/Range. Do the same for the holiday table. Giving the holiday query a short, clear name like Holidays makes it easier to reference later.
- Check the date types. In the main query, confirm both date columns show a calendar icon in the header. If they show ABC (text), click the icon and choose Date. Wrong types are the single most common reason this formula fails.
- Add a custom column. Go to Add Column > Custom Column and give it a name, for example Working Days. In the formula box, enter the range builder:
List.Dates([Start Date], Duration.Days([End Date] - [Start Date]) + 1, #duration(1,0,0,0)) - Test the list before going further. Click OK and look at the new column. Each cell shows a List, not a number. Click one cell's whitespace to preview the dates underneath. They should start on the start date and end on the end date, inclusive. If you see an error instead, the dates are probably text or the sum is negative.
- Filter out weekends. Add another custom column and wrap the list in a filter. Using the previous column name:
List.Select([Working Days], each Date.DayOfWeek(_, Day.Monday) < 5)
Power Query treats Monday as day 0, so this keeps days below 5, which are Monday to Friday. If your working week starts Sunday, adjust the comparison. - Count the result. Add a third custom column:
List.Count([Working Days])
assuming you used the filtered column as input. You now have a number of business days per row. - Exclude holidays. Reference the holiday table under the holiday query and pull its date column into a list. In the main query, change the count formula so it compares the two lists first:
List.Count(List.Difference([Working Days], Holidays))
where Holidays is the name of the step or column holding your holiday list. Power Query has no separate holiday argument, so this list difference replaces it. - Clean up and load. Right-click the intermediate list columns and choose Remove so only the final count remains. Rename it something human, then go to Home > Close & Load to send the data to a worksheet or the data model.
- Test one row by hand. Pick a row you can verify, count the weekdays on a calendar, subtract any holiday that falls inside the range, and compare. This catches off-by-one errors in the inclusive range before they spread across a report.
Common Mistakes
- Forgetting the +1.
Duration.Daysmeasures the gap between dates, not the number of dates. Without+1you lose the end date and get a count one day short whenever the end date is a weekday. - Subtracting dates stored as text. Text dates either error or produce wrong answers. Always set the type to Date first.
- Using
DateTimeinstead ofDate. Times of day make durations fractional and lists unpredictable. Strip the time component, or wrap withDate.From. - Assuming a six-day week. The
< 5filter removes Saturday and Sunday. If your business works Saturdays, you need a different test, such as excluding only the days you specify. - End date before start date. The list formula errors. Decide whether such rows should be zero or excluded, and handle them with a conditional
if. - Hard-coding holidays. Lists change each year. Keep them in a table so a refresh picks up edits without touching the query.
Tips
- Add a null-safe check at the start of the formula, for example only building the list when both dates are not null, so blank rows return null instead of an error.
- Build the logic once and make it a function, then invoke it on any table with two date columns.
- Name steps descriptively as you go. Stepping into a nested custom column later is much easier when the steps read like sentences.
- Keep the list columns visible until the count works, then delete them. Hiding problems behind a cleanup step wastes time.
- If the holiday table grows often, sort and remove duplicates in its query so the difference stays fast and accurate.
Troubleshooting
Errors in the new column. Click the error text to see the message. An expression error usually means a type problem or a negative date range; a null in either date column will also break the arithmetic.
Counts look too low. Check that you did not filter weekends before counting the full range, and confirm the +1 is present. Also open one list to see whether the end date appears.
Counts look too high. The weekend filter may not have applied because you counted the unfiltered column. Verify which column the List.Count references.
Holiday subtraction returns odd numbers. Ensure the holiday list contains real dates, not text, and that it shares the same date range. Dates outside the range are harmlessly ignored; text values are not.
The query is slow. Very long ranges multiplied by many rows create huge lists. Limit to the rows you need, or compute counts for common ranges only.
If that did not work, rebuild the custom column step by step: first list the dates, confirm it, then filter, confirm again, then count. That narrows the fault to a single line.
Frequently Asked Questions
Does Power Query have a NETWORKDAYS function?
No. It is an Excel worksheet function. In Power Query the equivalent is a list of dates filtered to the days you count, which gives the same result.
How do I count days including Saturdays?
Change the filter so it excludes only Sunday, or supply your own list of non-working days and use List.Difference to remove them.
Can I exclude holidays automatically?
Yes, but only with your own holiday table. There is no built-in holiday calendar, so you maintain the dates and the query subtracts them.
Why is my result one day more than expected?
The range is inclusive of both the start and end dates. If you want an exclusive count, remove the +1 from the duration.
Can I reuse this on many tables?
Yes. Put the logic in a blank query and convert it to a function with two date parameters, then add a column that invokes it.