Daily DAX : Day 276 NETWORKDAYS

 The **NETWORKDAYS** function in Power BI DAX calculates the number of working days between two dates, excluding weekends (Saturday and Sunday) and optionally specified holidays. It’s useful for business scenarios where you need to measure time durations in terms of workdays, such as project timelines, employee attendance, or task durations.


### Syntax

```dax

NETWORKDAYS ( <StartDate>, <EndDate> [, <Holidays>] )

```


- **StartDate**: The start date of the period.

- **EndDate**: The end date of the period.

- **Holidays** (optional): A table or column containing dates to exclude as holidays.


### Return Value

An integer representing the number of whole working days between `StartDate` and `EndDate`, excluding weekends and any specified holidays.


### Key Points

- Weekends are assumed to be Saturday and Sunday.

- If `StartDate` is after `EndDate`, the result is negative.

- The function counts only complete days (e.g., it doesn’t account for partial days).

- The `Holidays` parameter typically references a table or column with holiday dates, often from a calendar table.


### Use Case Example

**Scenario**: A company tracks the number of working days taken to complete tasks, excluding weekends and public holidays.


1. **Data Setup**:

   - You have a table `Tasks` with columns `TaskStartDate` and `TaskEndDate`.

   - You have a `Holidays` table with a column `HolidayDate` listing public holidays (e.g., 2025-01-01, 2025-12-25).


2. **DAX Measure**:

   ```dax

   WorkingDays = 

   NETWORKDAYS(

       Tasks[TaskStartDate], 

       Tasks[TaskEndDate], 

       Holidays[HolidayDate]

   )

   ```


3. **Application**:

   - For a task starting on 2025-01-01 and ending on 2025-01-10, with 2025-01-01 as a holiday:

     - Total days: 10 (Jan 1 to Jan 10).

     - Excluded: 2 weekend days (Jan 4, Jan 5) and 1 holiday (Jan 1).

     - Result: `NETWORKDAYS` returns **7 working days**.

   - This measure can be used in visuals to analyze task durations, employee productivity, or project timelines.


### Practical Notes

- Ensure dates are in a valid format (e.g., using `DATE` or a date column).

- The `Holidays` parameter must reference a column or table expression returning dates.

- If no holidays are provided, only weekends are excluded.

- Use in combination with a calendar table for dynamic holiday lists or date ranges.


### Example in a Report

You can create a Power BI visual to show the average working days per task:

- Add the `WorkingDays` measure to a table or card visual.

- Filter by department or project to compare task completion times.



Comments

Popular posts from this blog

Daily DAX : Day 65 INFO.TABLEPERMISSIONS

Daily DAX : Day 55 PV