I have a report with begin date and end date parameters and is specifically meant for subscription that should serve 2 types of subscriptions:
1, One for previous fiscal week -->Begin date is first day of previous fiscal week and end date is last day of previous fiscal week.
2, One for previous day -->Begin date is previous day and end date is also previous day.
Dataset Datefields:
This is the dataset query results for both date parameters available and default values.
When I create subscription for previous day it only runs that day...after midnight that day, begin date and end date parameter values are blank and the subscription fails with a status message "The subscription contains parameter values that are not valid" values.
Subscription created for previous fiscal week is good for a week until the values previous fiscal week start and end dates change.
You are using a dataset for defaults and values for date parameters, which probably isn’t the best approach.
The way I have handled reports that I want to allow end users to subscribe to, and have the default date values vary depending on whether subscription was a daily, weekly, or monthly one, is to have an extra parameter that makes this possible.
The parameter I add to the report is one I call Period (or Report Period), and it has to be the first parameter in the report, or at least listed before the date parameters. The only values in the dropdown for this parameter are Daily, Weekly, and Monthly (if applicable). These can be whatever you need. Enter these manually as value options in the parameter in the report, since they are not expected to change very often. Based on what the end user chooses for this parameter when creating a subscription, the default date values change. This is done via an expression in the default value for the date parameters that evaluates the value chosen from the Period dropdown.
So, if the end user wants a daily subscription, they choose Daily from the Period parameter dropdown, and the default values for the start and end date parameters change to only include the prior day. If they choose Weekly, the start and end date parameters change to only include the prior week, and so on.
Here is an example for the start date parameter default value expression.
=Switch(Parameters!Period.Value = "Daily" , DateAdd(DateInterval.Day, -1, Today),
Parameters!Period.Value = "Weekly" , DateAdd(DateInterval.WeekOfYear, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)-1), Today)) ,
Parameters!Period.Value = "Monthly" , DateAdd(DateInterval.Month, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)-1), Today)))
For the end date parameter…
=Switch(Parameters!Period.Value = "Daily" , Today,
Parameters!Period.Value = "Weekly" , DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)), Today) ,
Parameters!Period.Value = "Monthly" , DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)), Today))
Warning!! Changing the Period value either in the report designer (preview), or online, will not cause the date values to automatically change right before your eyes. It will while creating (and thus executing) a subscription, however. I have never looked into why this is. I have other, less painful, things to fill my time.
Give this a try.
Related
I am new to report building with SSRS.
I am currently trying to have an expression in SSRS show a specific date depending on wether today's day is on a weekend or not. This I tried to achieve by utilizing the different date functions Microsoft provides in their documentation. This is what I got so far:
=IIF(WeekdayName(weekday(DateAdd(DateInterval.Day, -1, today()))) = 'Monday', CDate(DateAdd("d", -3, Parameters!DateTo.Value)),
IIF(WeekdayName(weekday(DateAdd(DateInterval.Day, -1, today()))) = 'Sunday', CDate(DateAdd("d", -2, Parameters!DateTo.Value)),
CDate(DateAdd("d", -1, Parameters!DateTo.Value))))
As you can see I am trying to have it so if today's day is Sunday or Monday the date value returned should be the one from last Friday else it should return yesterday's date.
In Report Builder I'm receiving an error message stating that there is an expression expected and I cannot save the file.
What am I missing here? Is there maybe a different approach to achieving this? Thanks for any help.
BR,
Philipp
I would do it like this... There may be more efficient ways but this would be my approach...
=IIF(
Weekday(Today())=7 OR Weekday(Today())=1
,DATEADD(DateInterval.Day, (Weekday(Today())+1) * -1, Today())
, Today()
)
Note This assumes you week starts on a Sunday, if not adjust the first part of the IIF to suit.
So here we are saying...
If today is Saturday (7) or today is Sunday(1) then, subtract the (current day number +1) from the current date, else return the current date.
I have created a report in VS2013. I have also created a Stored procedure that returns a dataset that works out Last_week_start, Last_week_finish, Last_month_start, Last_month_finish etc. I have done this so users can subscribe to these reports and get them emailed to them on a Monday for the weekly and on the 1st on the month for the monthly reports. Do I have to create separate reports for the weekly and monthly reports with different default parameters? ie Audit Report (weekly) and Audit Report (monthly) and maintain 2 reports or is there a more dynamic way to do this
The way I have handled reports that I want to allow end users to subscribe to, and have the default date values vary depending on whether subscription was a daily, weekly, or monthly one, is to have an extra parameter that makes this possible.
The parameter I add to the report is one I call Period (or Report Period), and it has to be the first parameter in the report, or at least listed before the date parameters. The only values in the dropdown for this parameter are Daily, Weekly, and Monthly (or whatever is applicable). These can be whatever you need. Enter these manually as value options in the parameter in the report, since they are not expected to change very often. Based on what the end user chooses for this parameter when creating a subscription, the default date values change. This is done via an expression in the default value for the date parameters that evaluates the value chosen from the Period dropdown.
So, if the end user wants a daily subscription, they choose Daily from the Period parameter dropdown, and the default values for the start and end date parameters change to only include the prior day. If they choose Weekly, the start and end date parameters change to only include the prior week, and so on.
Here is an example for the start date parameter default value expression.
=Switch(Parameters!Period.Value = "Daily" , DateAdd(DateInterval.Day, -1, Today),
Parameters!Period.Value = "Weekly" , DateAdd(DateInterval.WeekOfYear, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)-1), Today)) ,
Parameters!Period.Value = "Monthly" , DateAdd(DateInterval.Month, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)-1), Today)))
For the end date parameter…
=Switch(Parameters!Period.Value = "Daily" , Today,
Parameters!Period.Value = "Weekly" , DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)), Today) ,
Parameters!Period.Value = "Monthly" , DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)), Today))
Warning!! Changing the Period value either in the report designer (preview), or online, will not cause the date values to automatically change right before your eyes. It will while creating (and thus executing) a subscription, however. I have never looked into why this is.
One report, dynamic date ranges based on a parameter.
Give it a try.
Updating report parameters based on parameter selection? (SSRS)
the above seems to be applicable on list based parameters.
But how do we apply for Dates: say the requirement will be
if i create a list parameters for This day,This week,This month etc. the Start date should change based on earlier selections.
How do we acheive this?
You can set your list parameter to be of type integer, then set available values to be:
Then in your date parameter, set the default value to be along the lines of:
=switch(Parameters!ReportType.Value = 1, dateadd(dateinterval.day, -1, Today()), Parameters!ReportType.Value = 2, DateAdd(DateInterval.Day, 2-WeekDay(Today()), DateAdd(DateInterval.Day, -7, Today())), 1=1, dateadd(dateinterval.day, -1, Today()))
This checks the value of the previous parameter and sets the default start date based on that (weekly or daily). The final condition in the switch is 1=1 - this is always true, so is the equivalent to an else condition. It's not required, I just like it in case something weird happens and they manage to get there.
Note
If you select one of the values from the first parameter (e.g. "Daily") and the default values for the date parameter(s) change, changing the first parameter to "Weekly" will not update the date parameter. This is a known issue with cascading parameters - the only way to change them at that point is to either do it manually or refresh the report.
I am trying to set a default parameter value in SSRS report. I want to test the current date to see if it equals the first day of the week (in my case Monday). If it is the first day of week, then I want the default value to be current date minus 2 days, if it is not the first day of the week then I want the default value to be current date minus 1 day.
I seem to have a syntax problem but it doesn't tell me where. My parameters are StartDate and EndDate.
this is what I've tried:
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today(),DateAdd("d",-1,today())
this is the generic error I get:
The value expression for the report parameter 'StartDate' contains eror:[BC30201] Expression expected.
Where am I going wrong?
You are trying to use Sql syntax in a SSRS VBA expression. SSRS VBA allows very similar expressions for date manipulation to Sql, the main difference being the use of the DateInterval enum.
So your expression needs to use VBA syntax:
=IIF(Weekday(Today, FirstDayOfWeek.Monday) = 1, DateAdd(DateInterval.Day, -2, Today), DateAdd(DateInterval.Day, , -1, Today))
It appears that you are missing a closing parentheses after the first logical part of the if statement and another to close the statement.
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today()),DateAdd("d",-1,today()))
I have an SSRS 2005 report that has a dataset for to an Oracle database. The report that i have essentially just pulls all data back from an audit log. This report works perfectly fine and i have scheduled thi to run and send an email using the new subscription method within SSRS.
The only issue i have is i want the report to run on the last day of the month (its set up to do this alreday) and run the report based on that month only. Getting the report to run specifically for a month is what im unsure on? I though i would be able to set parameters within the report but these only enable my user to select a calendar date?
Is there a DATEADD or DATEPART type of function i can use to complete this task?
Regards
B
Best bet would be to set up a dynamic date default for the date patameter at the report level, and set up the subscription to use this default value, so whenever the subscription runs it would automatically have the appropriate date.
Probably the easiest thing to do is set the parameter as the current date, if that would work, e.g. something like =Today(). So that will be calculated whenever the subscription runs.
You can set the default value for whatever you need; first day of the current month, etc. You should able to set whatever value you need without too much trouble.
So for the first day of the month something like:
=DateSerial(Year(Today()), Month(Today()), 1).
Users running the report ad-hoc could just reset the parameter as required.
I'm assuming the report handles the amount of data to return correctly assuming the right data parameter is sent.
2 Parameters #DateFrom and #DateTo
Default Value for #DateFrom that outputs the first day of the current month:
=DateAdd("d",-Day(Today())+1,Today())
Default Value for #DateTo that outputs the last day of the current month:
=DateAdd("d",-Day(Today())+1,DateAdd("m",1,Today()))