I have an SSRS report with a date parameter which defines the start of the week that we wish to report on. I want the default date for this parameter to display as follows based on a nested IIF statement that uses the current day of the week to determine which date the parameter should display as default (I have included example dates for January in the brackets):
- Monday (18th) = Monday Last Week (11th)
- Tuesday (19th) = Monday Last Week (11th)
- Wednesday (20th) = Monday Last Week (11th)
- Thursday (21st) = Monday Last Week (11th)
- Friday (22nd) = Monday This Week (18th)
- Saturday (23rd) = Monday This Week (18th)
- Sunday (24th) = Monday This Week (18th)
I have attempted to write an expression to accomplish this but so far I have been unable to get the parameter to display as I require. The expression I have written is:
=IIF(DateInterval.Weekday = 1, 'Monday = Monday Last Week
DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
IIF(DateInterval.Weekday = 2, 'Tuesday = Monday Last Week
DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
IIF(DateInterval.Weekday = 3, 'Wednesday = Monday Last Week
DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
IIF(DateInterval.Weekday = 4, 'Thursday = Monday Last Week
DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
IIF(DateInterval.Weekday = 5, 'Friday = Monday This Week
DATEADD("d", 1 - DATEPART(DateInterval.WeekDay, Today,FirstDayOfWeek.Monday), Today),
IIF(DateInterval.Weekday = 6, 'Saturday = Monday This Week
DATEADD("d", 1 - DATEPART(DateInterval.WeekDay, Today,FirstDayOfWeek.Monday), Today),
IIF(DateInterval.Weekday = 7, 'Sunday = Monday This Week
DATEADD("d", 1 - DATEPART(DateInterval.WeekDay, Today,FirstDayOfWeek.Monday), Today),
Today
)
)
)
)
)
)
)
Is what I am attempting possible? And if so where am I going wrong? Also, I am aware that comments will cause the expression to error, I have added comments to the example code to make it more readable.