Forum Discussion
Calculating Sum between 2 dates excluding weekends
- Anonymous2 years ago
Hi Grimfandango227 ,
I'm sorry I misunderstood you before, your requirement is to calculate the value of 7 consecutive working days, for not the value of 7 consecutive days that are working days. Let's start again.
My date today is March 7th.
The Table data is shown below:Please follow these steps:
1. Use the following DAX expression to create a table named ‘Table’Table = CALENDAR(DATE(2024,1,1),DATE(2024,12,31))2. Use the following DAX expression to create a column named ‘IsWeekend’ in ‘Table’
IsWeekend = IF(WEEKDAY('Table'[Date],2)>5,TRUE(),FALSE())3. Use the following DAX expression to create a table named ‘Table2’
Table 2 = FILTER('Table','Table'[IsWeekend] = FALSE())4. Use the following DAX expression to create a column named ‘Column’ in ‘Table2’
Column = COUNTROWS('Table 2') - RANKX(ALL('Table 2'), 'Table 2'[Date],,DESC) + 15. Use the following DAX expression to create a table named ‘Table3’
Table 3 = FILTER('Table 2','Table 2'[Date] >= TODAY() )6. Use the following DAX expression to create a table named ‘Table4’
Table 4 = FILTER('Table 3','Table 3'[Column] = MINX('Table 3',[Column] + 6))7. Use the following DAX expression to create a measure named ‘SevenWorkDay’
SevenWorkDay = VAR StartDate = TODAY() VAR EndDate = MAXX(FILTER('Table 3','Table 3'[Column] = MINX('Table 3',[Column] + 6)),[Date]) RETURN CALCULATE(SUM('DOMO_Sales_Line'[Outstanding]),'Table'[Date] >= StartDate && 'Table'[Date] <= EndDate,'Table'[IsWeekend] = FALSE())8. The model relationships are as follows:
9. Fianl output
I've uploaded my test file so you can check it out.
Best Regards,
Wenbin Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Good Afternoon,
So I was able to follow all the steps you listed above (Thanks for that) but it would appear that weekend days are still being counted within the calculation. I'll show some data below for example.
1. Let's take this specific Item for example
Theoretically by using your formula looking out 7 days from today, we should have a total of 2,700 because today +7 days (excluding weekends) should give us that total.
Here is my finished formula
Unfortunately, it looks like it is still counting Sat. and Sunday when looking out 7 days.
If you see any errors in my work here please let me know and any help would be greatly appreciated.
Thanks!
Hi Grimfandango227,
I would recommend you look at amitchandak's answer to the question. This should resolve your query.
Networkdays is the standard function in Excel to determine business days between 2 dates. This should be able to help identify the # of days and was added to Power BI in ~July 2022.
It's important to note that Networkdays is slightly different to Workday. Workday calculates the # of days exclusive of the start date, whilst Networkdays is inclusive of the start date.
In excel this would mean you write "NETWORKDAYS([start date], [end date], [omit holidays])-1" to remove the extra day. The formula does stipulate it is inclusive on the documentation page, but give it a try and see if it comes out correct:
NETWORKDAYS function (DAX) - DAX | Microsoft Learn