所以我有一个表达式来计算两个日期之间的工作日数(不包括这些日期)。但这个表达似乎给出了我想要的相反结果,我不知道为什么。这是表达式:
=iif(IsNothing(Fields!End_Date.Value) or IsNothing(Fields!Report_Submitted_Date.Value) or Fields!Report_Submitted_Date.Value>Fields!End_Date.Value,"Invalid Data",
(DateDiff(DateInterval.day,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)+1)
- (DateDiff(DateInterval.WeekOfYear,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)*2)
- IIF(Weekday(Fields!End_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!End_Date.Value,1) = 7,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 7,1,0)-2)
因此,我从这个表达式得到的结果是,结束日期小于报告提交日期的每种情况我得到文本Invalid Data
,其余的是#Error
或负数。< / p>
现在我知道我可以通过切换True
和False
子句来解决这个问题,但我想理解为什么这些结果会被切换,因为据我所知:
IF结束日期或报告提交日期为空
或者如果结束日期大于报告提交日期,我应该获得Invalid Data
文本。
感谢任何答案。
编辑1:
所以我已经将表达式从IIF改为开关。
=switch(
IsNothing(Fields!End_Date.Value),"Invalid Data",
IsNothing(Fields!Report_Submitted_Date.Value),"Invalid Data",
Fields!Report_Submitted_Date.Value <= Fields!End_Date.Value, "Invalid Data",
True, "Good Data"
)
这给了我预期的结果,但是,如果我用表达式更改Good Data
来计算两个日期之间工作日的差异,我仍会得到#Error
。看起来当我执行此操作时,它无法将Report Submitted Date
识别为Nothing
。改变表达式如下:
=switch(
IsNothing(Fields!End_Date.Value),"Invalid Data",
IsNothing(Fields!Report_Submitted_Date.Value),"Invalid Data",
Fields!Report_Submitted_Date.Value <= Fields!End_Date.Value, "Invalid Data",
True, ((DateDiff(DateInterval.day,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)+1)
- (DateDiff(DateInterval.WeekOfYear,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)*2)
- IIF(Weekday(Fields!End_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!End_Date.Value,1) = 7,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 7,1,0)-2)
)
结果: