iif语句返回错误的结果

时间:2016-02-22 17:44:41

标签: reporting-services ssrs-2008 ssrs-2008-r2

我正在使用这些表达式将我的数据分组到

列中
=CountDistinct(iif((Fields!I_Sch_Close.Value >= DateSerial(Year(Now()), Month(Now()), "1")
AND Fields!I_Sch_Close.Value <= DateSerial(Year(Now()), 
Month(Now()), "1").AddMonths(1).AddDays(-1)), 1,0))
=CountDistinct(iif((Fields!I_Sch_Close.Value >= DateSerial(Year(Now()),
Month(Now()), "1").AddMonths(1) AND Fields!I_Sch_Close.Value <= 
DateSerial(Year(Now()), Month(Now()), "1").AddMonths(2).AddDays(-1)), 1,0))
=CountDistinct(iif((Fields!I_Sch_Close.Value >= DateSerial(Year(Now()),
Month(Now()), "1").AddMonths(2) AND Fields!I_Sch_Close.Value <= 
DateSerial(Year(Now()), Month(Now()), "1").AddMonths(3).AddDays(-1)), 1,0))
=CountDistinct(iif((Fields!I_Sch_Close.Value >= DateSerial(Year(Now()), 
Month(Now()), "1").AddMonths(3) AND Fields!I_Sch_Close.Value <= 
DateSerial(Year(Now()), Month(Now()), "1").AddMonths(4).AddDays(-1)), 1,0))

这是结果

enter image description here

以下是查询返回的数据

enter image description here

正如您所看到的那样,4月和5月字段显示返回1个结果,当我认为它应该显示为0. No COE(I_Sch_Close) Column应该是11但是使用以下表达式读取2:

=CountDistinct(iif(ISNOTHING(Fields!I_Sch_Close.Value),1,0))

我做错了什么?

1 个答案:

答案 0 :(得分:0)

No COE的以下表达式中的IIf语句返回1或0

=CountDistinct(iif(ISNOTHING(Fields!I_Sch_Close.Value),1,0))

这些的不同数量不能超过2.相反,您需要计算表达式为True的出现次数。尝试这样的事情:

=Count(IIf(<expression>, 1, Nothing))