SSRS Report subscription date parameters - reporting-services

The thing that I want to do is as follows
I have a SQL reporting services report that takes date parameter (I have two parameters as Run_Report_From_Date_PARM and Run_Report_To_Date_PARM. These dates are picked from the Datepicker). I want to create a subscription to the report that will run on 1st of every month and show the data for the prior month.
While making subscription if i choose 2016-08-01 for Run_Report_From_Date_PARM and 2016-09-01 for Run_Report_To_Date_PARM then the report is generating always with that date range only. But i need the date ranges modify automatically after every month(like for the next month From date should be 2016-09-01 and to date should be 2016-10-01 ).

What is simplest is to just use expressions to set the default values for these parameters.
For a start date of the first of last month:
=DateAdd("m", -1, DateAdd("d", 1 + -1 * DatePart("d", Today()), Today()))
For an end date of the last of last month:
=DateAdd("d", -1 * DatePart("d", Today()), Today())
However, if you don't want these to be the default values when executing the report, you can set up a hidden boolean parameter that you only set to true in the subscription settings. That can be useful if you need to include formatting or default value tweaks in the subscription version of a report.

Related

SSRS date parameter : report start date should be yestardays on daily bases but on monday it should be friday's date

In my report I want to populate date parameter automatically. on daily bases date need to be select previous day (today()-1) , but on Monday it need to select Friday date.
please help me to write a function around this
I have date parameter in my report.
You can achieve this using Weekday(). Make sure the parameter has the Date/Time data type, and use this expression as the default value:
=DateAdd(DateInterval.Day,
IIF( Weekday(Today(),0) = 1, -3, -1),
Today())
The function Weekday(Today(),0) will equal 1 when today's date is a Monday. If true, you subtract three days from today's date to get the previous Friday. If not, you subtract 1 to get yesterday.

Get all dates for a specific day of week (e.g. Monday) between 2 dates

Consider given 2 dates between 2015-01-01 and 2015-01-30, I need to find the dates for every Monday and every Sunday during that period.
I have a report, the user needs to select a date range, and from the date range it calculates each first-day-of-week and last-day of week and passes it in that way.
How it currently works in SSRS is
exec storedprocname
#BD=N'798211,798654,798664,798826',
#CGNo=N'47',
#SCGNo=N'4701,4702,4703,4704,4705,4706,4707,4708',
#ProductClass=N'1,2,4,3',
#ProductCode=N'1020',
#Region=N'772',
#FirstDayOfWeek='2014-01-06 00:00:00',
#LastDayOfWeek='2014-01-12 00:00:00'
User selects multiple Mondays and Sundays, the report is a matrix table and matrix's on first day of week
FirstdayOfWeek = '2014/06/09,2014/06/16'
LastdayOfWeek = '2014/06/15,2014/06/23'
What I need is a date range the user selects this and it will still pass it in the same way
#startdate '2015/01/01' = Thursday (for this select current week's Monday)
#startdate '2015/02/01' = Sunday
You can use SSRS inbuilt function WEEKDAYNAME
=WEEKDAYNAME(DATEPART("dw", Fields!myDate.Value)
OR
=WEEKDAYNAME(DATEPART("w", Fields!myDate.Value)
You can use weekdayname function to filter your dataset or matrix or use in Iff expression.
If you want to handle it in SQL Server you can use dataname function.

SSRS daily subscription for monthly report

I have a SSRS report which is executed and delivered daily to emails. The report calculates some numbers for the 1st date of the month to the (d-1)th date (d being the day when it is executed). So the default parameter values in this report are :
Start_date :=DateSerial(Year(Date.Now), Month(Date.Now), 1)
End_date :=DateAdd("d",-1,Today())
The problem is on 1st of every new month , the start date evaluates to 1st of new month and the end date becomes the last date of previous month. This makes the report non-sensical on 1st of every month.
What should we do to avoid this and force the expression to evaluate 1st of the new month as start and end date ?
For the End Date, perhaps check if it's the 1st of the month and then default to the current date (i.e. the 1st) if it is:
=Iif(
Day(DateTime.Today) = 1,
DateTime.Today,
DateAdd("d",-1,DateTime.Today)
)
But I'm assuming there is a reason your are using today-1 as the end date, so this could mean your report shows nothing for the 1st day of the month...

Date Range in Reporting services 2008

I have created one report where i want to pull the records from specified date range
I have two parameters i.e. StartDate and EndDate. Both are date/time data type.
What I want to do is set the default date for the StartDate parameter as +7 days from today's date, and have the EndDate as +7 days from the StartDate?
Basically the reports need to show everything for the following week
E.g. If the report is created today (Monday 22nd Sept); it would show data between Monday 29th to Sunday 5th.
Please let me know how I would specify this as an expression under the parameters, or could this be done within the DataSet?
Put the StartDate Parameter's default value as =now.AddDays(7)
And EndDate Parameter's default value =Cdate(Parameters!StartDate.value).AddDays(7)

SSRS adding default time to a date parameter

I have an SSRS report with two parameters that are datetimes. Of course the date selector doesn't allow you to select times to go with the dateTIME, that would make too much sense. So my idea was to give the datetime parameters a default time. For example, if I wanted the default value of a parameter to be today's date at 8:30 AM, how would I do that?
So if today was 9/4/2013 I want to see exactly this: 09/04/2013 8:30 AM.
I have tried all kinds of formatting. The closest I got was doing this:
=CDate(Format(Today(), "MM/dd/yyyy") & " 8:30 AM")
But I have never been able to get the seconds to not show up because you always have to convert this back to a datetime from a string, otherwise you get an invalid type error, and CDdate ALWAYS displays the seconds.
It seems like you're trying to format the date directly in the parameter's default value, is that correct? The thing is, CDate() converts a string into a DateTime; and DateTime objects do have seconds. If you don't want to display those seconds in your report, you should convert the date into a formatted string, such as:
=Format(Parameters!yourParameter.Value, "MM/dd/yyyy hh:mm")
In order to set a default time to your date parameter, you could also use something like this in the parameter default value:
Today().AddHours(8).AddMinutes(30)
I tried everything I could find on SO to format these dates but couldn't get it to drop the zero's in the parameter as a date field or just appear blank. I was using SSRS 2005 so was struggling with its clunky / buggy issues.
My workaround was to add a column to my custom [DimDate] table in my database to pull dates. I added a column that was simply a string representation of the [date] column. I then created 2 new Datasets that pulled in the following queries for 2 defaults for my 'To' & 'From' date defaults -
'from'
SELECT Datestring FROM dbo.dimDate WHERE [date] =
(SELECT max(date) FROM dimdate WHERE date <= GETDATE() )
'to'
SELECT Datestring FROM dbo.dimDate WHERE [date] =
(SELECT max(date) FROM dimdate WHERE date < DATEADD(month,-3,GETDATE()))
Use this =DateAdd("s",-1,DateAdd("d",1,Parameters!dateTo.Value)) works for me adjust your time by changing to hours.