The NETWORKDAYS function in DAX (Data Analysis Expressions) is a powerful tool that allows you to calculate the number of working days between two dates. It’s an essential function when dealing with business data that involves dates, such as project timelines, employee attendance, or sales cycles. In this guide, we’ll take a deep dive into the NETWORKDAYS function, exploring its syntax, usage, and some advanced scenarios.

Syntax

The syntax of the NETWORKDAYS function is as follows:

NETWORKDAYS(<startDate>, <endDate>, <holidays>)
  • <startDate>: The start date of the period.
  • <endDate>: The end date of the period.
  • <holidays>: (Optional) A list of dates that are considered holidays and not counted as working days.

The function returns the number of working days between the start date and the end date, excluding weekends and optionally excluding specified holidays.

Basic Usage

Let’s start with a basic example. Suppose you have a project management table with columns for project start dates and end dates, and you want to calculate the number of working days for each project.

Here’s how you can do it with the NETWORKDAYS function:

Working Days = NETWORKDAYS(Projects[Start Date], Projects[End Date])

This formula creates a new column called “Working Days” that calculates the number of working days for each project.

Including Holidays

If you have a list of holidays that you want to exclude from the working days, you can include them in the NETWORKDAYS function.

Suppose you have a Holidays table with a Date column that lists all the holiday dates. Here’s how you can exclude these holidays from the working days calculation:

Working Days = NETWORKDAYS(Projects[Start Date], Projects[End Date], Holidays[Date])

This formula calculates the number of working days for each project, excluding weekends and the specified holidays.

Advanced Usage

The NETWORKDAYS function can also be used in more advanced scenarios. For example, you can use it to calculate the average number of working days for all projects, or to filter projects based on the number of working days.

Here’s an example of calculating the average number of working days for all projects:

Average Working Days = AVERAGEX(Projects, NETWORKDAYS(Projects[Start Date], Projects[End Date], Holidays[Date]))

This formula calculates the number of working days for each project and then calculates the average of these values.

And here’s an example of filtering projects based on the number of working days:

Long Projects = FILTER(Projects, NETWORKDAYS(Projects[Start Date], Projects[End Date], Holidays[Date]) > 30)

This formula returns a table that includes only the projects that have more than 30 working days.

Conclusion

The NETWORKDAYS function in DAX is a powerful tool for calculating the number of working days between two dates. By understanding and effectively using this function, you can gain valuable insights into your business data and make more informed decisions. So, keep exploring the capabilities of the NETWORKDAYS function, and take your Power BI skills to the next level!

Categorized in: