Michigan Man
Michigan Man

Reputation: 101

SSRS IIF Date evaluation

I have the following code

=IIf(Fields!Freeze.Value, Fields!effectivedate.Value, IIF(Month(Fields!effectivedate.Value) <> Month(Now()), Format(Now(), “MM/dd/yyyy”) , Fields!effectivedate.Value))

A. In the first IIF statement I check to see if the Fields!Freeze.Value is true, if its true then It displays Fields!effectivedate.Value (IIf(Fields!Freeze.Value, Fields!effectivedate.Value)

B. In the second IIF statemenet I check if the Fields!effectivedate.Value is the current month, If it is the current month then it displays Fields!effectivedate.Value, If it is not the current month then it displays the current date.

I would like assistance on the following.

In the first IIF statement ,>>> IIf(Fields!Freeze.Value, Fields!effectivedate.Value, I want to evaluate a new value Fields!FreezeDate.value

  1. If the Fields!Freeze.Value = true then check to see if the Fields!effectivedate.Value is 30 days or more less than Fields!FreezeDate.value. A. If its 29 days or less than Fields!FreezeDate.value then display Fields!effectivedate.Value B. If its 30 days or more less than the Fields!FreezeDate.value then display the Fields!FreezeDate.value

Example 1

 Fields!FreezeDate.value  = '12/30/2012'
 Fields!effectivedate.Value = '11/15/2010'


 then Display the Fields!FreezeDate.value

Example 2

 Fields!FreezeDate.value  = '12/30/2012'
 Fields!effectivedate.Value = '12/15/2010'


 then Display the Fields!effectivedate.Value

How would I write this in SSRS code?

Please ask for further clarification if i have failed to explain something properly.

Upvotes: 3

Views: 16167

Answers (2)

Paul Alan Taylor
Paul Alan Taylor

Reputation: 10680

I suspect the thing you're missing is knowledge of the DATEDIFF function.

http://msdn.microsoft.com/en-us/library/aa337092%28v=sql.90%29.aspx

IIF(
  DATEDIFF(DAY, Fields!FreezeDate.Value, Fields!effectiveDate.Value) => 30,
  Fields!FreezeDate.Value, 
  Fields!effectiveDate.Value )

Above, we're using DATEDIFF.

First parameter is the Time measurement we want to measure differences between. DAY.

Example:-

DATEDIFF(DAY, '2013-01-01', '2013-01-15') should yield 14.

Tying it all up, we're calculating the day difference between FreezeDate and effectiveDate. When that value is over 30, display the effectiveDate. Otherwise, display FreezeDate.

You may need to play around to get the desired result. Your English description of your logic was not great. Did the best I could under the circumstances.

Upvotes: 0

Ian Preston
Ian Preston

Reputation: 39566

As I understand the requirement, you'll need to add another IIf() section which checks the difference in days between the two dates, then displays effectiveDate if the difference is < 30 days:

=IIf
(
  Fields!Freeze.Value
  , IIF
  (
    DateDiff(DateInterval.Day, Fields!effectiveDate.Value, Fields!FreezeDate.Value) < 30
    , Fields!effectiveDate.Value
    , Fields!FreezeDate.Value
  )
  , IIF
  (
    Month(Fields!effectivedate.Value) <> Month(Now())
    , Format(Now(), “MM/dd/yyyy”)
    , Fields!effectivedate.Value
  )
)

Upvotes: 2

Related Questions