Reporting Services has many expressions that can manipulate date fields. These expressions can be used just about anywhere in SSRS including object properties, displayed data, and parameters.
Recently I’ve worked on some projects that required date parameters to do things that you would typically see in an Analysis Services cube. My client needed to see data brought back Week to Date, Month to date, Year to date, and on with a rolling week. My first suggestion of course was to create a cube to not only to do these calculations but get many other benefits. Unfortunately, they did not take my advice so I had to use the SSRS expression language to return the results they were looking for.
I thought this made for a great blog topic so I could refer back to these whenever I need them. All the reports had at least two parameters for start date and end date. I needed to change the default values so they would default to show the above date range (YTD, MTD…etc).
End date would always have the current date or Today() in the expression language. If you want time included then use Now(). The default value of the start date parameter will use the DateAdd function to return back a date that is a set number of units back. The DateAdd function is constructed like this:
DateAdd(interval, number, date)
|Interval||This is the interval you want to add (Ex. Days, Months, Years…)|
|Number||Numeric value that represents the number of intervals you want to add|
|Date||The date to perform the addition to.|
Expression I use to change my parameter default values. These could be written many different ways and actually use VB in the customer code are but I wrote them this way if you’re not a VB expert.
Month over month
Week over week
Year over Year
Notice in the YTD and WTD expression I’m calling a DateInterval function that is actually a Visual Basic function but does not require you do add anything to the custom code section of your report.