SSRS Expression to Get last 12 months - reporting-services

I have created a ssrs report and this report display last 12 months data. I have 2 parameters startDate and Enddate.
The End date is always the current month and I want the start date to be the last 12 months. For example if my (End Date) current month is JAN 2018. I want my start date to be Feb 2017.
I have below expression but this give me Jan 2017 date for my start date.
=DateAdd("M", -12,Today())

Try this expression for the start date parameter default value.
=DateAdd(DateInterval.Year, -1, DateAdd(DateInterval.Month, 1, Parameters!EndDate.Value))
Here's what the parameter values would equal:

Related

Getting the Week Number for the Month Crystal Reports Formula

I have a Crystal Report Grouped by (Day,Week,Month).
I want to be able to display the "Week Number" for the month. Ex: 1st Week Of July, 2nd week of July, 3rd Week of July, etc. on the "Week" Group Header.
I have tried using a Formula
Totext(DatePart("ww", {Command.TransactionDate}),0)
But the result is the "Week Number" for the year EX: 33,34,35. Any help would be very much appreciated
Use an expression like this:
datevar yourDate := currentdate;
Datepart("ww",yourDate)+1
- Datepart("ww",yourDate - Day(yourDate)+1)
of course, replace the variable assignment with your date.
The logic is to get the week number of the date (plus 1) and subtract the week number of the 1st of the current month.

How to set a default parameter date for the beginning of the month to yesterday date

I have build an SSRS report. I set a default date parameters as following:
startdate : take the first day of the month.
EndDate : take yesterday date.
This code for the beginning of the month
=DateSerial(Year(Now()), Month(Now()), "1").AddMonths(0)
This code for yesterdate date
=DateAdd(DateInterval.Day,-1,CDate(FormatDateTime(Now,DateFormat.ShortDate)))
The date works perfectly until, a new month comes, the result will be like this:
startdate: 01. 5 2019
end date: 30. 4 2019
where it should be :
startdate: 01. 4 2019
end date: 30. 4 2019
how can i make sure if a new date comes , it will take the first day of the previous month.
You should add an IIF statement to check if today is the first day of the month. The following expression should do what you need.
=IIF(DatePart(DateInterval.Day, Today()) = 1,
DateSerial(Year(Now()), Month(Now())-1, 1),
DateSerial(Year(Now()), Month(Now()), 1))
Just change your StartDate to reference yesterday's date:
=DateSerial(Year(Today.AddDays(-1)),Month(Today.AddDays(-1)),1)

SSRS - Date parameter - Previous month specific date

I am Looking for a previous month specific date.
i.e. when the report is run on 25th of current month, the start date should always be previous month 25th.
Your expression for start date can simply be..
=DATEADD("m", -1, now())
If the run date is 25th October the start date will be 25th September.
If the run date is 31st March, the start date will be 28th of February, which is as close as you can reasonably get.
Found a solution for this.
Answer: =dateadd("m",-1,dateserial(year(Today),month(Today),25))
The above expression always looks for previous month 25th date, regardless when we run the report. for example if you always want to run on 11th of previous month then change the 25 to 11 on the above expression.
To get the same date of the previous month, just look for the previous month using DateAdd function like:
=DateAdd(DateInterval.Month,-1,Today())

SSRS date from previous year but with the same weekday name selected

I am trying to get last year's date but with the same week day as the one selected. Meaning that if the user selects Dec 5th 2013 which is a Thursday, the formula would select Dec 6th 2012 which is also a Thursday. Any help would be greatly appreciated.
Find/Replace "Today()" with the name of the field or parameter.
=Switch (
WeekDay(Today())-WeekDay(DateAdd("d",-365,Today())) = 0, DateAdd("d",-365,Today()),
WeekDay(Today()) > WeekDay(DateAdd("d",-365,Today())), DateAdd("d",(-365)+ABS(WeekDay(Today())-WeekDay(DateAdd("d",-365,Today()))),Today()),
WeekDay(Today()) < WeekDay(DateAdd("d",-365,Today())), DateAdd("d",(-365)-ABS(WeekDay(Today())-WeekDay(DateAdd("d",-365,Today()))),Today())
)

SSRS 2008 week number calculation of current month

I need to construct a data parameter in SSRS 2008 where if the current week number is 1 then I use the first day of the previous month and if not then I use the current day.
I.e. today is week 4 therefore would utilize today's date
If today was march 2, then the week would be week 1 and I would utilize the first of the previous month, feb 1
note: weeks must follow calendar weeks.
Thanks in advance for your assistance
You can set the parameter default using the following expression:
=IIf(Day(Today()) <=7
and DatePart(DateInterval.WeekDay, Today(), FirstDayOfWeek.Monday)
>= DatePart(DateInterval.WeekDay, DateSerial(Year(Today()), Month(Today()), 1), FirstDayOfWeek.Monday)
, DateAdd(DateInterval.Month, -1, DateSerial(Year(Today()), Month(Today()), 1))
, Today())
So:
If today is one of the first seven days of the month, and the day of the week number is >= the day of the week of the first of the month
=> First week, so use the first day of the previous month
=> Else use the current date.