I need the last week Monday and Sunday , say today is March 18th hence the SSRS expression
should return
March 10th -Monday
March 16th -Sunday
I was able to get it using SQL
select dateadd(d,(2-datepart(dw, getdate())), dateadd(ww,-1,getdate()))
select dateadd(d,(1-datepart(dw, getdate())), getdate())
not sure how to get it done via SSRS expression
SSRS VBA allows very similar expressions for date manipulation to Sql, the main difference being the use of the DateInterval enum. Without checking your expressions, it will convert to SSRS VBA as follows:
Last Monday:
=DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today))
Last Sunday:
=DateAdd(DateInterval.Day, 1-WeekDay(Today), Today())
To get Sunday from Last Week :
(Note: Last Week Sunday is different from Last Sunday).
=DateAdd(DateInterval.Day, 1-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today))
To get Saturday from Last Week :
=DateAdd(DateInterval.Day, 7-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today))
with Weekdays values as below:
1 - Sunday
2 - Monday
3 - Tuesday
4 - Wednesday
5 - Thursday
6 - Friday
7 - Saturday
Related
How do I get the first and last day of the previous year in SSRS for default dates
tired wth DATEADD function but getting an error
You can use DATESERIAL() to do this easily
DateSerial just take 3 integer values (year, month, day) to return a date.
First day
=DateSerial( year(today()) - 1, 1, 1)
Last Day
=DateSerial( year(today()) - 1, 12, 31)
You don't show what you tried so we can't explain what you are doing wrong.
If I needed to get the 1st day of the previous year, I would take the current year, subtract the number of days from 1 and then subtract a year.
With DATEADD, the first day of last would be:
=DATEADD("yy", 1, DATEADD("d", 1 - DATEPART("dy", TODAY), TODAY))
While the last day is actually simpler:
=DATEADD("d", 0 - DATEPART("dy", TODAY), TODAY)
How to display Last week Sunday and last week Saturday from current date in SSRS ?
In sql server we can find the last week Sunday and last week Saturday from todays date(CurrentDate='19-02-2020') as
select DATEADD(wk, -1, DATEADD(wk, DATEDIFF(wk, 0,getdate()), -1))-- for sunday
select DATEADD(wk, DATEDIFF(wk, 0, getdate()), -2) --for saturday
So how we can write an default expression in the SSRS Parameters?
This assumes that the first day of the week is a Sunday, if you configuration is not like this then you will need to adjust the expressions to correct the offset
For Last Saturday use:
=DATEADD(DateInterval.Day, Weekday(Today()) * -1, Today())
For Last Sunday use:
=DATEADD(DateInterval.Day, (Weekday(Today()) -1) * -1, Today())
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)
I built a SSRS 2005 report on a SSAS 2005 cube. The report has start date and end date parameters from Time dimension. I need to set the default values to be last Sunday and last Saturday separately. (financial week is from Sunday to Saturday)
E.g.
Start date: [Time].[Day].&[20140309]
End date: [Time].[Day].&[20140315]
How can I do it dynamically? I mean for this week is above dates, but for next week, it should be 16 March, 22 March. I know how to do it in T-SQL, which will involve some calculation with system date, but MDX?
You can use some VBA Date functions available in MDX:
StrToMember('[Time].[Day].&['
+ Format(DateAdd('d', - DatePart('w', Now(), 1), Now()), 'yyyyMMdd')
+ ']'
)
should give you the last Saturday before today, and
StrToMember('[Time].[Day].&['
+ Format(DateAdd('d', - DatePart('w', Now(), 1) - 6, Now()), 'yyyyMMdd')
+ ']'
)
the last Sunday before that.
The second argument of DateAdd('d', ...) is the number of days to add. And as this is negative here, we go back in time that many days. DatePart('w', ...) returns the weekday number (Sunday = 1, Monday = 2, ...). Thus, if you subtract "weekday number" days from today, luckily you are already at last Saturday. And subtracting six more days, you arrive at the last Sunday before that.
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.