Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi Everyone,
I'm trying to calculate the difference between the two dates using the DATEDIFF() function and I want to omit weekends from it. below is the DAX I'm using currently:
Solved! Go to Solution.
Hi,
As per our understanding you are attempting to calculating the difference between the two dates using the DATEDIFF() function.To omit weekends from the date difference calculation in Power BI using DAX, you need to adjust your logic to correctly exclude Saturdays and Sundays. The issue with your current DAX is that it calculates the total difference in days and then subtracts the count of weekend days, but this approach doesn't account for the fact that weekends are already included in the total day count.
Here’s a revised version of your DAX formula that correctly excludes weekends:
Diff =
VAR StartDate = SELECTEDVALUE('2C_Table'[StartDate])
VAR EndDate = SELECTEDVALUE('2C_Table'[EndDate])
VAR TotalDays = DATEDIFF(StartDate, EndDate, DAY)
VAR WeekendDays =
CALCULATE(
COUNTROWS(Dates),
FILTER(
Dates,
Dates[Date] >= StartDate &&
Dates[Date] <= EndDate &&
(WEEKDAY(Dates[Date], 2) >= 6) // 6 = Saturday, 7 = Sunday
)
)
VAR BusinessDays = TotalDays - WeekendDays
RETURN
IF(BusinessDays < 0, 0, BusinessDays)
Explanation:
StartDate and EndDate: These variables store the start and end dates from your table.
TotalDays: This calculates the total number of days between the start and end dates using DATEDIFF.
WeekendDays: This calculates the number of weekend days (Saturdays and Sundays) between the start and end dates. The WEEKDAY function is used to identify weekends (6 = Saturday, 7 = Sunday).
BusinessDays: This subtracts the number of weekend days from the total days to get the number of business days.
RETURN: The final result is returned, ensuring that if the calculation results in a negative value, it returns 0.
Thanks!
Hi,
As per our understanding you are attempting to calculating the difference between the two dates using the DATEDIFF() function.To omit weekends from the date difference calculation in Power BI using DAX, you need to adjust your logic to correctly exclude Saturdays and Sundays. The issue with your current DAX is that it calculates the total difference in days and then subtracts the count of weekend days, but this approach doesn't account for the fact that weekends are already included in the total day count.
Here’s a revised version of your DAX formula that correctly excludes weekends:
Diff =
VAR StartDate = SELECTEDVALUE('2C_Table'[StartDate])
VAR EndDate = SELECTEDVALUE('2C_Table'[EndDate])
VAR TotalDays = DATEDIFF(StartDate, EndDate, DAY)
VAR WeekendDays =
CALCULATE(
COUNTROWS(Dates),
FILTER(
Dates,
Dates[Date] >= StartDate &&
Dates[Date] <= EndDate &&
(WEEKDAY(Dates[Date], 2) >= 6) // 6 = Saturday, 7 = Sunday
)
)
VAR BusinessDays = TotalDays - WeekendDays
RETURN
IF(BusinessDays < 0, 0, BusinessDays)
Explanation:
StartDate and EndDate: These variables store the start and end dates from your table.
TotalDays: This calculates the total number of days between the start and end dates using DATEDIFF.
WeekendDays: This calculates the number of weekend days (Saturdays and Sundays) between the start and end dates. The WEEKDAY function is used to identify weekends (6 = Saturday, 7 = Sunday).
BusinessDays: This subtracts the number of weekend days from the total days to get the number of business days.
RETURN: The final result is returned, ensuring that if the calculation results in a negative value, it returns 0.
Thanks!
Hi @SamInogic ,
Thank you for sharing the DAX and its explanation. However, it's giving a blank value when I used the given DAX.
Regards,
Mahesh
Hi @Anonymous - Your approach is on the right track, but the issue comes from how you’re filtering weekends in your _weekend variable. The ALL(Dates) function removes the applied filter context, but you need to ensure that the count correctly aligns with the StartDate and EndDate range.
check the modified measure:
Diff =
VAR _TotalDays = DATEDIFF(SELECTEDVALUE('2C_Table'[StartDate]), SELECTEDVALUE('2C_Table'[EndDate]), DAY)
-- Count the weekends between StartDate and EndDate
VAR _WeekendCount =
CALCULATE(
COUNTROWS(Dates),
Dates[Date] >= SELECTEDVALUE('2C_Table'[StartDate]) &&
Dates[Date] <= SELECTEDVALUE('2C_Table'[EndDate]) &&
Dates[DayName] IN {"Saturday", "Sunday"}
)
-- Subtract weekend count from total days
VAR _WorkDays = _TotalDays - _WeekendCount
-- Ensure no negative values
RETURN MAX(0, _WorkDays)
Hope it helps
Proud to be a Super User! | |
Hi @rajendraongole1 ,
Thank you for sharing the DAX and its explanation. However, it's giving a blank value when I used the given DAX.
Regards,
Mahesh
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!