Updating report parameters for dates based on list - reporting-services

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.

Related

SSRS Cascading Params without a dataset

I've done many a cascading param in SSRS but ALL have used datasets, passing in a param value into a query, this time I want to know if a date selection can be done using only expressions.
Periodtype parameter has a value list of 'Day' Or 'Quarter' (those are the labels, the values are "D" and "Q").
I've set the default values of the start and end dates via SSRS expression if periodtype value is "D" then set start and end date to be beginning and end of previous day and if "Q" then similar with previous quarter.
This works when you start up the report, changing the default period type (D or Q).
It won't allow the date to be calculated dynamically when changing the periodtype, can it be done without queries, using just params and expressions, thank-you?
If I've understood your question correctly, I think the issue is not so much to do with datasets, but a long standing issue with SSRS not refreshing parameters, or at least the defaults, even if you specify to always refresh it.
Typically you can force the update by changes the available values.
As an example ...
I set up 2 parameters, the first called PeriodType is a simple text parameter with two available values "Q" and "D", it also has a default value of "D"
The second parameter called StartDate is a Date/Time type.
The following three properties were all set to the exact same expression
Available Values: Specify Values - Label and Value properties
Default Values: Specify Values - Value property
Here is the expression which simply shows todays date if "D" is chosen or the 1st Jan if Q is chosen purely for illustration.
=IIF(Parameters!PeriodType.Value = "D", today(), CDATE("2022-01-01"))
I also set the advanced properties "Always Refresh" option.

Subscribing to a report with different default parameters

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.

Comparing todays date against first day of the week

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

Report Builder 3.0 Updating Parameter Panel

I have a report that has StartDt, and EndDt as parameters. When a user leaves these blank, I default StartDt to yesterday, and EndDt to today. That works fine the the actual parameter send to SQL. But is there a way to update the SSRS Parameter Panel to show the user what dates were defaulted?
I know I could just make the parms required, but I'd rather default the dates like this so users can just put in there account(s) and move on.
Set the default value expressions for each date parameter using the standard date/time functions.
You can set today as:
=Today()
Yesterday as:
=DateAdd(DateInterval.Day, -1, Today())
See How to: Add, Change, or Delete Default Values for a Report Parameter for more details.
Edit after comments
Say you have the following parameters:
StartDt and EndDt are just set up as Date/Time:
Set the Default Values expression for each parameter using the expressions above, i.e. =Today() and =DateAdd(DateInterval.Day, -1, Today()):
Now, when you load the report for the first time the two parameters are already populated with the Default Values:
Users can then just leave the dates as the defaults as they're already set, or change them as necessary.

SSRS Set Date/Time parameter to NULL based on previous paremeter's selection

I have 3 parameters in an SSRS report: rptFiscalyearId, rptStartDate, rptEndDate.
rptFiscalyearId is a predefined select list of fiscal years.
rptStartDate and rptEndDate are both of type "Date/Time" (i.e., datepickers) and both have "Allow null value" set to true in parameter properties.
The default value of rptFiscalyearId is 0 (meaning "All").
What I'm trying to do is make it so that if the user picks a different value for rptFiscalyearId, then the values for rptStartDate and rptEndDate will both be set to Null.
The only way I'm able to do this is to set the "Available Values" properties in rptStartDate and rptEndDate to an expression like "=IIf(Parameters!rptFiscalyearId.Value > 0, Nothing, Datetime.Now)". However, the problem with this is that by doing so, the parameter is changed to a select list instead of a calendar datepicker.
Is there any way of achieving what I'm looking for without converting my datepicker parameters to select lists?
Is there perhaps some way to do this programatically in the report viewer?
I don't think you can retain the date picker while setting the available values, but have you considered setting the default rptStartDate and rptEndDate values instead? That way, the users would still be to set the values via the date picker - although they would also be able to override the fiscal year start and end dates.