2017-02-23 109 views
1

我試圖將日期參數的默認值設置爲下個月的第一個工作日,即如果該月的第一天是星期六或星期天,則選擇以下星期一。 我有這個,但由於某種原因,當我嘗試運行報告時說它在本地報告處理過程中發生錯誤,我無法弄清楚發生了什麼問題。誰能幫忙?下個月的第一個工作日

= 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())))) 

回答

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 
    )) 
+0

完美作品,謝謝 – Quazi200

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) 
) 

假設你一週的第一日星期一。

希望它有幫助。

+0

完美作品,謝謝 – Quazi200

相關問題