SSRS parameter default to most recent 1st April

时间:2015-06-15 14:31:48

标签: sql reporting-services parameters

I have a requirement for an SSRS parameter that will be for a start date of the most 1st April, so today it will report from 1/4/2015 with 10 weeks data, but after the 1/4/16 it will default to 1/4/16.

Can anyone help with this please?

I can find most recent month, or current month etc, but this one is a little tricky. Thankyou.

I am using SQL Server 2012 and Visual Studio 2010

1 个答案:

答案 0 :(得分:1)

You could use the following expression:

=IIF(Today() >= DateSerial(Year(Today()), 4, 1), DateSerial(Year(Today()), 4, 1), DateSerial(Year(Today()) - 1, 4, 1))

The idea is to check if the 1st of April of the current year has been reached (Today() >= DateSerial(Year(Today()), 4, 1)).

  • If yes, take the 1st of April of the current year: DateSerial(Year(Today()), 4, 1)
  • If no, take the 1st of April of the previous year: DateSerial(Year(Today()) - 1, 4, 1)