These were the requirements given for an SSRS report:
A dropdown for quickly changing dates to preset ranges, such as
"YTD" or "Last 12 months"
The selected option in the dropdown should be stored in the database for each user, and retrieved when opening the report
The dates should be able to be edited directly despite what has been selected
The issue is that parameters don't cascade their default values without refreshing, requiring the report to be re-run to take effect and store the option, then to be refreshed to actually populate the "Default Values" for the date. This can be fixed by using "Available Values" instead, but means that the date fields will no longer be editable.
This may seem easy to some, but it stumped me for a bit. This is the solution that now works.
The parameters that need to be used are RangeOption, StartDate, EndDate, StartDateCustomInput, EndDateCustomInput
First, we need to create a table in the database to store the user's report preferences. SSRS has a built-in field for the user ID, so this can be passed to remember what the user's last "Range Option" was.
We follow this up by creating two stored procedures, one that gets the last run option for the user, and one that sets it. The SSRS username is the built-in user ID field.
The setting procedure should be put into a dataset, which will refresh and store the "Range Option" when the dropdown option is selected.
The dropdown parameter will use the getter procedure as its "Default Value". Under Advanced, make sure this is set to "Never Refresh".
To get the dates to update automatically without the need to re-run the report and refresh, we need to use "Available Values" instead. Plug in whatever expression you want to use, which references the dropdown parameter (#RangeOption) The catch is that this makes the date unable to be edited.
To make the date editable, a second date parameter needs to be created for our start and end dates. These dates will use "Default Values" that simply grab whatever is in the original start and end date parameters. Then, point all of our report items to the editable date fields (#StartDateCustomInput,#EndDateCustomInput).
Now, the dropdown alters the original date parameters, which then alter the editable date parameters, without running the report. The editable parameters can be altered first if the user wants, and the report will run with whatever is in these custom date parameters. The downside is that the original date parameters do not seem to cascade if they are hidden/internal, so you will likely need to have duplicate visible date parameters.
For some reason, the default values for the date parameters cascade in this way, but not the original approach.
Related
I have a SSRS report that takes a parameter and executes a stored procedure to generate a report with it.
the parameter is a values from a table that I have user select from a dropdown
let's say 15 options that are passed as parameters to each execution.
AAAA
AAAB
AAAC
...etc
is there any way I can setup the report so it will execute with each parameter and generate a report?
the issue is that now the user has to manually select 1st parameter, generate the report and then export the file result to excel.
what I want to do is a way for the user to select multiple parameters and export just one file containing all of them (the stored procedure can't take more parameters because of the way is coded depends on receiving one parameter only)
so it would have to schedule multiple executions of the stored procedure to create the report and then export this. is this possible? (as a note, the amount of parameters will change frequently so I need to give the option of selecting multiples from a list that is populated from a query to database)
and to clarify, the Stored Procedure needs to take only one parameter, this is not to be solved by sending multiple parameters to operate by using a splitter or similar, as the parameter received by the SP is used in calculations depending of order, (to not go into detail with the SP, just need to take one parameter per execution)
As you already have a report that handles a single option then you can do this easily using sub reports. Don't worry about the length of this answer it actually quite simple.
I would make a copy of the existing report to be safe....
Change the existing report to only accept a single parameter value if if doesn't already. Save this report, this will be your sub-report so let's say it's called mySubReport
Next create a new blank report.
Add a dataset (called say dsParameterList) that will give you the list of options you want the user to choose from (I guess this will be the same as your current report?). For example if it was a list of companies it might look something like SELECT CompanyID, CompanyName FROM myCompanyTable
Next add a parameter called say #options, make sure it is set to be multi-value and set the available values to use a query and point this to dsParameterList. Set the value and label fields as required.
Now create another dataset called dsLoop for example. This dataset will contain a list of selected parameter values. Using the company example from earlier the dataset query might look something like this. SELECT CompanyID, CompanyName FROM myCompanyTable WHERE CompanyID IN (#options)
Next add a table to your report and remove columns so that only 1 remains. Set the dataset property of the table/tablix to dsLoop. This means we will generate 1 row for every selected parameter value.
In the detail row right click in remaining textbox and choose 'Insert Subreport'. Now right-click the subreport placeholder and set the properties to point to the report we saved earlier (mySubReport in this example).
Whilst still in the sub report properties, click the parameters tab and add a new entry, choose the parameter in the left column and set the value in the right column to be the value from dsLoop that you want to pass to the subreport. In our company example this would probably be [CompanyID]
That's it. You run the report and choose from the parameter list, when you click View Report the dsLoop query runs and gives us a list of just those selected Companies, the report body is generated with a row for every row in the dsLoop dataset which in turn runs the subreport with a different parameter passed in each time.
Optionally You can right-click the rowgroup under the main design window and set the 'pagename' property to a value. In the Company example this might be =Fields!CompanyName.Value. When the report is exported to Excel each sheet in the workbook will be named with the name of Company
I have a set of reports than currently run from a 'Select Report' form. Users select the report name and the start and/or end dates they want to view, and the query underlying the chosen report looks at the controls on the form to filter the report to the selected dates.
We now want to automatically run some of these reports every Monday morning, to send out via email. The start and end dates for the reports will be Date() and Date()+14. I know how to code to run the report and attach it to email, but I can't work out how to programmatically pass dates to the form's underlying query, instead of it looking to the form controls.
I've searched for the answer but can only find answers explaining how to do one or the other, but not if it's possible to do both using the same report.
I've tried to use parameters in the report's underlying query instead, but then I get prompt boxes for the date paramaters when I open the report from the form, even though dates have been selected on the form and are passed through to the report as expected.
I've also tried to pass the dates via openargs instead of looking directly to the form controls, but then I can't work out how to pass those openarg values into the query, only to controls on the report. That means the displayed start and end dates are correct, but the date filtering isn't applying to the report. From stepping through it, the report loads the data before the OnLoad code runs which sets the controls to the openargs values, so they are null at the point the data is filtered.
Any help is much appreciated, I'm a bit stumped on the best approach from here. Thanks.
I have reached a working solution for this, it may not be the most elegant but it allows me to use a single report in the two scenarios of opening automatically for a specific date range, or opening at the users request with user specified dates.
I have amended the reports so their default record source uses Date() and Date()+14 for the report date range.
When the report is opened by a user from the "Report Selection" form, "User" is passed through via OpenArgs. The OnOpen event of the form checks the value of OpenArgs and if it is set to "User", changes both the report's record source and the controls that display the report date range to use the dates entered by the user on the selection form.
#kostasK. thank you for all your input, you helped me get to this solution.
I have an SSRS (2016) report that accepts a date parameter. The user selects a date and the report runs and returns one page per customer. The report also has a data driven subscription which when triggered, emails the output relevant to the customer.
My current approach is to have a text box that only some users can see and clicking the text box triggers the subscription . I do this by :
Inserting the parameter selected by the user into a table when the user clicks "View Report" button and then use the following to trigger the subscription:
EXEC msdb.dbo.sp_start_job #job_name ='job name to be sent out'
The data set for the subscription/ report then uses the parameter inserted into the table to do it's thing. This all works fine.
The problem arises when more than one person runs the report.. the second persons trigger can potentially over write the first persons parameter insert resulting in the wrong set of data being sent out..
My questions is.. is there a better way to trigger data driven subscriptions where the report needs parameter values - but the parameter value cannot be predetermined?
If my approach is acceptable, how can I eliminate the overwriting of parameter values?
Better still, how can I determine the correct parameter and pass it to the subscription? e.g. session id / user id.. etc.,
Any ideas or alternate implementations are welcome..
I've run into the same issue before, where a default table value is overwritten during processing from another user. The way I resolved it was adding a column to the default table for the HOST_ID or HOST_NAME. It's a bit of a pain because then you have pass that parameter to the report as well.
SELECT HOST_ID(), HOST_NAME()
OR
In a report parameter you can use the following expression default value to get the current user.
=Right(User!UserID, Len(User!UserID)-instr(User!UserID, "\"))
Note: Your data-driven subscription will fail if you set this as a report variable. As a parameter, it will work.
I have a SQL database and using SSRS to produce reports. They are both 2012 version. The data is well water levels that are record every hour. Originally I have the report displaying ALL of the data for a user selected well (dropdown list). The user can also select the start and end date (text box) But the well levels don't change that much every hour unless there is a significant rain/flooding event. So I want the user to have the option to choose only the noontime values for each day. Is there a way to have a checkbox that would either 1) change actual query the report is using or 2) include filter that says only display 12:00:00? The parameter options seems to want to include a date and I only want to filter by time.
Thanks
I think the solution for you is to add a parameter to your report to be able to select what information to show with 2 possible values - All / Noon only. Then add a new field / calculated field to your dataset to indicate which ones are noon values. Then use the new parameter to filter the values showed in the report.
Hope it makes sense.
I have a form that is linked to a table in Access. I have an additional field which displays the sum of a few fields in the table. This field on the form is not connected to the table. I have the sum displayed on the form but what I noticed is that the sum does not appear until I move away and navigate to another record and come back to the original record. I don't see the addition as soon as I enter values in the respective fields.
Can someone help with this issue?
It sounds like you need to add some code to the After Update events of the controls for the fields used in the sum. That code can call the .Refresh method of the control that performs the calculation and update the total.
Edit
Another possibility is that there could be ambiguity between control values and field values if they have the same name. In Design View for a report if you drag a field from the "Field List" and drop it into a report then Access creates a report control with the same name as the field. This can confuse matters later because if any expressions refer to =[SomeColumn] it's not clear whether that refers to the field or the control. Often simply renaming the controls to something like txtSomeColumn can help if a report is acting strangely.