Search code examples
reporting-servicesssrs-2012ssrs-tablix

DateDiff function in SSRS (report server) gives error?


Im trying to find the days gap between two dates using DateDiff function. I have 2 datasets defined. If companycode is 'AB' then from one dataset else from another dataset I retrieve data.

Here is my expression. When I change to preview mode, it shows redmark to the first First(Fields!PeriodFrom.Value line. Why? (after generating report that field shows #Error

What Im doing wrong here?

 =IIF(Parameters!CompanyCode.Value="AB", 
    DateDiff("d",First(Fields!PeriodFrom.Value, "ABReportData"), First(Fields!PeriodTo.Value, "ABReportData")),
    DateDiff("d",First(Fields!PeriodFrom.Value, "XYReportData"), First(Fields!PeriodTo.Value, "XYReportData")))

Solution

  • I think there are two possible scenarios. First one is the expression

    =First(Fields!PeriodFrom.Value, "ABReportData")
    

    doesnt return a value. Add a column with this expression and check if you get a value.

    If the value is correct, make sure that the DateDiff() function gets a date:

    =IIF(Parameters!CompanyCode.Value="AB", 
         DateDiff("d",
                  CDate(First(Fields!PeriodFrom.Value, "ABReportData")), 
                  CDate(First(Fields!PeriodTo.Value, "ABReportData"))
                  ),
         DateDiff("d",
                  CDate(First(Fields!PeriodFrom.Value, "XYReportData")), 
                  CDate(First(Fields!PeriodTo.Value, "XYReportData"))
                  )
         )