Question

I am working on a report in Microsoft SQL Server Report Builder and I am trying to write an expression that will display only the next 5 business days from today (i.e. a table has 5 columns and it starts from today and proceeds for the next five business days). If the day is a Saturday or Sunday, which using my enumeration value would return a 6 or a 7 using the Weekday function, you would skip ahead to the next business day. Currently I have this expression for the first column after the column with today's date

IIf(Weekday(DateAdd("d",1,Today()),2)=6,DateAdd("d",3,Today()),
(IIf(Weekday(DateAdd("d",1,Today()),2)=7,DateAdd("d",2,Today()),
DateAdd("d",1,Today()))))

and it doesn't work. I believe this is because if we have a day like Wednesday, Thursday, or Friday, not enough days are being skipped over for the weekend days.

Was it helpful?

Solution

If we can assume that you are going to start from a business day then there is a simple formula we can use:

=IIF(6 - WeekDay(Today()) - X < 0, DateAdd("d", X + 2, Today()), DateAdd("d", X, Today()))

where X is the number of days that column is from the start date.

Unfortunately, it breaks down if the start date is a Saturday or Sunday but if you only need it for business days then you are good to go.

OTHER TIPS

I think you have to use previous column value instead of using Today() So inthe first column it will be the current date. (Apply the same formula if it can start from weekend days). I think switch case is more easy in this condition.

Formula for current day column

=switch (
Weekday(today) = 6, dateadd("d", 2, today),
Weekday(today) = 7, dateadd("d", 1, today),
Weekday(today) < 6, today
)

In the second column instead of today() use "Fields!previous_column_name.Value".

=switch (
Weekday(dateadd("d", 1, Fields!previous_column_name.Value)) = 6, dateadd("d", 3, Fields!previous_column_name.Value),
Weekday(dateadd("d", 1, Fields!previous_column_name.Value)) = 7, dateadd("d", 2, Fields!previous_column_name.Value),
Weekday(dateadd("d", 1, Fields!previous_column_name.Value)) < 6, dateadd("d", 1, Fields!previous_column_name.Value)
)

In third column use the second column as previous_column.

Hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top