SSRS Cascading Parameters - reporting-services

At the run time user will select the country for which the report
should run.
Next we will show all states of the selected country on parameter
screen.
Next we will show all cities of selected state on parameter screen.
How can we achieve this?

I'm not really sure, but here's what i think:
Create Your Parameter
Set your parameter value based on others parameter value, and send it to parameter data set to retrieve its data. (maybe you can use expression to do this)
Hope it would help :)
Regards,
David Tan

I could achieve it.
I created first a dataset for my report with Country, State and City fields.
After this, first parameter is country, user will select the country at run time.
After this, I have added another dataset2 to select all the states based on first parameter. I created another parameter to show multiple states. For this parameter I provided 'available values' as the second dataset viz., dataset2. This dataset2 was accepting parameter country and populating the states at the run time. I provided 'default values' as well as dataset2.
This same way I implemented the 'city' parameter. It worked.
Thank you!

Yes we can achieve that.
Let say you have two dropdownlist as a parameters, A and B.
You give A list of data from dataset
for B, you use dataset too to retrieve the data, but when you create dataset for B add filter and set parameter A as its value.
Add Filter for paramater B and set A as its value
Hopefully it would help :)
Thankyou.

Create three different parameters as country,state and city in your dataset and add one line to the dataset query as where country = #country and state = #state and city = #city.
Now coming back to your question, If your sql has duplicate countries,state or cities it wil return duplicate values so create three different datasets for three parameters.Like "Select Distinct country from Person.country" and state is dependent on country so write query for state as "Select Distinct state from Person.Country where Country = #country" and same goes for city.
Hope this answers the question

Related

Depending Parameters in a text box (SSRS 2008-R2)

I am working on a SSRS Report and I have two Parameters in the Prompt section, EmployeeID and EmployeeName respectively.
EmployeeName prompt depends on the EmployeeID prompt selected, can the EmployeeName be populated in a textbox once EmployeeID is selected.
Right now EmployeeID is being shown in a drop-down and the user have to go to the drop-down and select it, can it be done in a textbox?
Any help would be greatly appreciated!
Create your main report dataset (dsMain for exmaple) with a query something like
SELECT * FROM myTable WHERE EmployeeID = #EmployeeID
I'm assuming you have the first parameter setup and working correctly to return your list EmployeeIDs. For this example we'll call this parameter EmployeeID/
Create another dataset (called for example, dsEmployeeName) with a query something like
SELECT EmployeeName from myEmployeeTable WHERE EmployeeID = #EmployeeID
In the second parameter (the one you want showing in a text box), leave the 'Available Values' blank and set the 'Default Values' to be from a query. Choose dsEmployeeName as the dataset and choose EmployeeName as the Value.
NOTE This will only work the first time round. If you choose another value from the drop down, the name will not be updated.
I don't know your exact requirements but if you can get both the ID and name together, why do you need two parameters, one of which does nothing really as it's not passed to the report?

SSRS parameters based on previous parameter

In my report I have a parameter which allows the user to choose one or multi-options.
Driver 1,
Driver 2,
Driver 3
I have another parameter that would only be valid if they chose Driver 3 from the previous parameter.
AAA,
BBB,
CCC
So maybe the user would choose Driver 1 and Driver 3 and then choose BBB. How can I have the report provide all the data for Driver 1 and only BBB for Driver 3?
Are the lists of parameter values coming from the database? If so you can use the result of the first parameter to filter the query for the second.
For example. If we wanted to be able to select from a list of geographical regions and then from there choose from a list of countries that exist in those regions we could do something like this.
Create a new dataset called say dsRegions and get a list of regions from the database with something like
SELECT RegionID, RegionName From dbo.Regions
Create a new parameter #regions and set it to be multi-value and set the available values to be from a dataset. select dsRegions and use the ID column as the value and name column as the label.
Create another dataset say dsCountries but this time the query will look something like this.
SELECT CountryID, CountryName FROM dbo.Countries WHERE RegionID IN (#regions)
Note: It is important to use IN (#regions) and not = #regions or the query will fail when more than one region is selected.
Create a new parameter #countries, set it up as we did with the previous parameter but this time pointing it at dsCountries
This way, anytime the user selects a new region or regions, the #regions parameter is updated, then the countries list will be re-queried and populated.
Finally, the #countries parameter would be passed to the main dataset for the report.
Assuming your 1st and 2nd parameters have a similar relationship then you should be able to adapt this generic example easily.

Searching a database in Report Builder 3.0

I am not sure if this is possible in Report Builder or not. I want to put a text box in a Report Builder report and then search the database for a specific person and display that in a subreport. Is this possible and, if so, how would you suggest I do it? I have tried researching it online without success.
This part will produce a parameter into which your user can type whatever they want
You need to set up your report to use parameters. You can set these parameters up to require user input either from manual entry or by picking from a pre-defined list.
Assuming you are returning your data using a SQL query, you can then reference these parameters in your dataset script. If for example you had a parameter called FirstName and another called Surname, and you only wanted to return values in your data set that matched both exactly, you would reference these parameters like so:
select PersonID
,FirstName
,Surname
,OtherDetails
from PersonTable
where FirstName = #FirstName
and Surname = #Surname
If you would rather have more of a 'search' type function, you can use the SQL like operator and wildcards, though bear in mind this will have a potentially very detrimental effect on your query performance:
select PersonID
,FirstName
,Surname
,OtherDetails
from PersonTable
where FirstName like '%'+#FirstName+'%'
and Surname like '%'+#Surname+'%'
This part shows you how to change that parameter so it provides a drop down menu. This part is optional.
If you want to provide a list of available options to select from, you can create a parameter that has a list of 'Available Values'. These can either be manually typed in by yourself - hard coding them in to the report design - or you can make them data driven by basing the parameter on a second dataset.
To get that list of people, you would want to return the ID of the person you are looking for as well as the details that are end-user friendly to be visible in the report:
-- select distinct so we have no duplicates
select distinct PersonID as Value -- Value is what is used to the query. This ideally will be a uniquye identifier
,FirstName
+ ' '
+ Surname as Label -- Label is what the user sees. This can be a bit more verbose and detailed
from PersonTable
order by Surname -- Specify how you want the options ordered
,FirstName
If you set this dataset as the source by selecting Get Values From A Query in the parameter options, you will see the drop down list appear when you run the report. Users can then select one, click Run Report and have their selection impact the data that is returned.

Report Builder 3.0 Forward Dependency Report Parameter

I have a report that I am working on that will do the following:
Return results based first on the community selected by the user.
Filter to find alike addresses within the community, based on the number of square feet at each address.
Set the end date (a column within the data table) to a user defined parameter for use in a WHERE at the end of the query.
The relevant information is stored in the following places:
Community: ub_subdivision.descr
Address: ub_serv_loc_addr.location_addr
SqFt: arp_ops.dbo.vw_ub_serv_loc_classifications.SqFt
I have setup the query with 3 parameters:
#Community
#Months
#Address
When the user is running the report, the following should happen (in this order):
The community parameter should populate the values stored in ub_subdivision.descr and allow the user to select the community they want from that list.
The address parameter should populate the values within the selected community from step 1, and allow the user to select the address they want from that list.
Based on the selected address, the query should store the value of the SqFt related to this address and use that in the WHERE statement as follows: WHERE (arp_ops.dbo.vw_ub_serv_loc_classifications.SqFt = #Address)
The months parameter should allow for user input to define how many months of data they want. This parameter is called in the query in the WHERE statement: WHERE (ub_bill_run.def_end_dt > DATEADD(m, -#Months, GETDATE())).
If I save the dataset and create a "table report" in Report Builder 3.0 it does the job of recognizing the various parameters and loading them into the Parameters folder and into the Datasets' parameters.
The problem I have is that I am not able to change the parameter properties to display Available Values and select "get from a query". If I go this route, and try to run the query I get an error that I am using "forward dependencies".
I need the #Address parameter to display the address field as the label, but store the sqft field as the value. This is the way I know how to do this and, unfortunately, it doesn't seem to work.
I would appreciate any insight anyone may have.
Thanks!
John
There is one way to solve this make sure the order should be in the order of
#Community
#Months
#Address
change order to:
#Community
#Address
#Months
just delete existing #month and again add it manually and save it.
i hope it will work for you.
You cannot have parameters based on your main data set.
The forward dependency error is caused because your data set is to be filtered by your parameter, yet it is depending on the same data set to find its' set of values. This is a sort of paradox.
When using queries to define the set of values for your parameters, make sure you create a new data set for each parameter.
Next, make sure the parameters are listed in the order you want them to run. Within the data sets for your parameters, you may use where clauses to make them dependent on one another in the order that they run.
In this example:
Parameter data set for Community:
SELECT DISTINCT ub_subdivision.descr
FROM [YOUR JOINED TABLES]
Parameter data set for addresses:
SELECT DISTINCT ub_serv_loc_addr.location_addr
FROM [YOUR JOINED TABLES]
WHERE ub_subdivision.descr IN (#Community)
Parameter data set for SqFt:
SELECT DISTINCT SqFt
FROM [YOUR JOINED TABLES]
WHERE ub_subdivision.descr IN (#Community)
AND ub_serv_loc_addr.location_addr IN (#Address)
You should also make a month data set for your #month parameter, however it is not dependent on the other parameters so I will leave that to you.
Hope this helps!

SSRS - Toggle subreports by parameter value

Requirements are as follows:
Grouping hierarchies should be swappable, for example Country > City > Department and Country > Department > City can be selected by the end user.
For the end user, there should be only one report.
The hierarchy that the user wants can be selected in a parameter value.
The data for the report should only be loaded once, since the query contains cpu intensive calculations.
I'm trying to do this by adding subreports for each hierarchy. Since hidden subreports are automatically loaded, I cannot toggle visibility of multiple subreports, or the data will be loaded twice. The ReportName property of the Subreport does not allow expressions. Can I use custom code to solve this, or what is a viable solution?
There are quite a few ways to do this.
If your dataset is embedded in your report, then I think the simplest way is:
Add your parameter, let's call it GroupingOrder, and hardcode your options: say set the Value to 1 for label of Country > City > Department and value of 2 for Country > Department > City
Add two calculated fields to your dataset within SSRS. (Right click on the dataset name and select "Add Calculated Field...". Name one "MiddleGroupName" and the other "InnerGroupName." Set the Field Source to formulas such as this for MiddleGroupName:
=IIF(Parameters!GroupingOrder.Value = 1, Fields!City.Value, Fields!Department.Value)
Use these calculated fields as normal groups in your report.
For bonus points, set the column titles based on your parameter: the column title for the middle group could be:
=IIF(Parameters!GroupingOrder.Value = 1, "City", "Department")
Another method could involve moving these calculations into the Grouping logic itself.
But I would steer clear of subreports in this case. They tend to hurt performance and create debugging difficulty.