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

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.

Related

SSRS Report subscription date parameters

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.

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.

How to do YTD, MTD calculations based on the Today()

I am very new to SSRS, I have below scenario.
I have to calculate measures for YTD, MTD, Last 7 Days and Previous day based on the today(). I need to use these YTD, MTD, Last 7 days and Previous day variables in the calculations while writing the IIF syntax
For example:
sum(IIF(Year="this year is Year to Date", value, sales)
sum(IIF(CreatedDate="the last 30days values ",sales)
Can any one please tell me how to achieve this
Thanks
You can use the YEAR function to get the year of a date field. An IIF statement is used to evaluate an expression (in your case if the date is within the current year) then the desired result if the expression is true then the result if false. So your YTD formula could look like:
=SUM(IIF(YEAR(Fields!YourDateField.Value) = Year(TODAY()), Fields!Sales.Value, 0)
This reads: The sum of (if the year = current year then Sales else 0).
The last 30 days is similar but you would use the DATEADD function to figure what the date was 30 days ago:
=SUM(IIF(Fields!YourDateField.Value >= DATEADD("d", -30, TODAY()), Fields!Sales.Value, 0)
https://technet.microsoft.com/en-us/library/aa337194(v=sql.100).aspx

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)