SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

SSRS Commonly Required Date Expressions

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)




This is the interval you want to add (Ex. Days, Months, Years…)


Numeric value that represents the number of intervals you want to add


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



=DateAdd("d",-(Day(today)-1), Today)

Week over week

=DateAdd("ww",-1, Today)


=DateAdd("d",-7, Today)



Year over Year

=DateAdd("yyyy",-1, Today)



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.

Devin Knight

Devin is a BI consultant at Pragmatic Works Consulting. Previously, he has tech edited the book Professional Microsoft SQL Server 2008 Integration Services and was an author in the book Knight's 24-Hour Trainer: Microsoft SQL Server 2008 Integration Services. Devin has spoken at past conferences like PASS and at several SQL Saturday events. He is a contributing member to the Business Intelligence Special Interest Group (SIG) for PASS as a leader in the SSIS Focus Group. Making his home in Jacksonville, FL, Devin is a participating member of the local users’ group (JSSUG).


No comments.

Leave a Comment

Please register or log in to leave a comment.