SSRS - Date parameter - Previous month specific date - reporting-services

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())

Related

Is there any function in sql to extract week?

I want to extract week from datetime, the output I want is 'YY/week', where week is the week of the year (eg '201724' is the 24th week in 2017).
The term "week of the year" is too ambiguous.
The week may start from Sunday, Monday or another weekday
The weeks enumeration in the year may start from 0 or 1
The weeks enumeration in the year may start from the week which includes January, 1 (and hence may be partial) or from first complete week of the year
The last week of the year, if it is partial, may be counted or not
Each DBMS has its own functions (sometimes original, always with original names) that can return the number of the week in the year on a given date. But they can not always take into account the above features.
Important addition provided by jarlh:
ISO 8601 (#4.3.4):
The first calendar week of a year is the one that includes the first Thursday of that year.
The last calendar week of a calendar year is the week immediately preceding the first calendar week of the next calendar year.
Week 1 is the first week of a year.
A calendar week starts on a Monday.
ISO 9075 doesn't even mention weeks.
SELECT TO_CHAR(TO_DATE('19-FEB-22') , 'IW') from DUAL;
To get the corresponding four-digit year, use
SELECT TO_CHAR(TO_DATE('19-FEB-22'), 'IYYY') FROM DUAL;
TO_CHAR() having so many options like this read more in Oracle manual or extract portation of date Extract Portion of Date Time Value
OutPut
You can use the following Mysql type query to extract.
SELECT DATE_FORMAT(BirthDate, " %u %Y") FROM Employees;
where the BirthDate date column in the database and the Employees is the table name.
This will result
49 1968
08 1952
35 1963
Week and the year.
in postgresql:
SELECT to_char('2016-12-31 13:30:15'::timestamp without time zone, 'yy/ww') ;
result:
16/53

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.

SSRS Expression to Get last 12 months

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:

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.

How To Get YEARWEEK() To See Sunday As The Start Of The Week?

I'm trying to get the YEARWEEK function to see Sunday as the 1st day of the week.
An example date is: Sunday 1st Mar 2009
Here is my sql
SELECT YEARWEEK('2009-03-01')
and the result is
-> 200909
Which is week 9. I believe it is telling me this is week 9 because it sees the sunday as the last day of the previous week.
How would I get this function to see sunday as the 1st day of the week and therefore return as week 10?
According to http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_yearweek, YEARWEEK has an optional second argument which controls this. YEARWEEK('2009-03-01', 0) should do what you want (but see the table of possible values under WEEK on that page).
this will do it:
SELECT YEARWEEK('2009-03-01')+IF(WEEKDAY('2009-03-01')=6,1,0);
EDIT: this is the better solution, for more information click here:
SELECT YEARWEEK('2009-03-01',0);
(but i don't know why you want to do this - 2009.03.01 is in week 9, not 10...)