Reputation: 232
I have the following expression to check parameter date values and replace from date if necessary:
=IIF(Parameters!FromDate.Value is nothing,
IIF(Parameters!ToDate.Value is nothing,
DateAdd("d",-30,Now()),
DateAdd("d",-30,Parameters!ToDate.Value)),
Parameters!FromDate.Value)
Only when the todate
is null, an error will get appear:
The added or subtracted value results in an un-representable datetime.
Did anybody face such a problem?
Upvotes: 0
Views: 3664
Reputation: 20560
The problem is that IIF
is a function, not a language construct so it evaluates both parameters before passing them to the function. That means DateAdd("d", -30, Parameters!ToDate.Value)
gets evaluated even when Parameters!ToDate.Value
is Null, thus giving you this error.
Try this instead:
=IIF(Parameters!FromDate.Value is Nothing,
DateAdd(DateInterval.Day, -30, IIF(Parameters!ToDate.Value is nothing, Today, Parameters!ToDate.Value)),
Parameters!FromDate.Value)
Upvotes: 2