下个月的第一个工作日

时间:2017-02-23 15:52:34

标签: reporting-services

我正在尝试将日期参数的默认值设置为下个月的第一个工作日,即如果该月的第一个是星期六或星期日,则选择下一个星期一。 我有这个,但出于某种原因,当我尝试运行报告时,它说在本地报告处理期间发生了错误,我无法弄清楚出了什么问题。有人可以帮忙吗?

= iif (datepart("dw", dateadd("m",1,DateAdd("d",1-DatePart("d",Today()),Today()))) = 7,
dateadd("m",1,DateAdd("d",3-DatePart("d",Today()),Today())),
iif (datepart("dw", dateadd("m",1,DateAdd("d",1-DatePart("d",Today()),Today()))) = 1,
dateadd("m",1,DateAdd("d",2-DatePart("d",Today()),Today())),
dateadd("m",1,DateAdd("d",1-DatePart("d",Today()),Today()))))

2 个答案:

答案 0 :(得分:0)

尝试:

=Switch(
WeekDay(DateSerial(Today.Year,Today.Month,1).AddMonths(1),FirstDayOfWeek.Monday)=6,
  DateSerial(Today.Year,Today.Month,1).AddMonths(1).AddDays(2),
WeekDay(DateSerial(Today.Year,Today.Month,1).AddMonths(1),FirstDayOfWeek.Monday)=7,
  DateSerial(Today.Year,Today.Month,1).AddMonths(1).AddDays(1),
true, DateSerial(Today.Year,Today.Month,1).AddMonths(1)
)

假设你是星期一的第一个星期日。

希望它有所帮助。

答案 1 :(得分:0)

=Today.AddMonths(1).AddDays(-Today.Day + 1).AddDays(
    SWITCH(
    Today.AddMonths(1).AddDays(-Today.Day + 1).DayOfWeek = DayOfWeek.Sunday, 1,
    Today.AddMonths(1).AddDays(-Today.Day + 1).DayOfWeek = DayOfWeek.Saturday, 2,
    True, 0
))

这将返回下个月的第1天:

Today.AddMonths(1).AddDays(-Today.Day + 1)

然后,switch语句根据下个月1日的日期确定要添加的天数:

.AddDays(SWITCH(
        Today.AddMonths(1).AddDays(-Today.Day + 1).DayOfWeek = DayOfWeek.Sunday, 1,
        Today.AddMonths(1).AddDays(-Today.Day + 1).DayOfWeek = DayOfWeek.Saturday, 2,
        True, 0
    ))