Parameters in a report - reporting-services

I am using microsoft reporting 2008 and I would like to set parameters in this report. I do not want to pull back a list that contains the same...such as year...I pull up my parameter and I have a hundred 2010...I just want one to appear in the parameter but I want my report to show all hundred. How do I do this?

I'm guessing you want to base your parameter selection on a query of available values that will appear in your report, so you have hooked it up to your dataset for your report.
Create another dataset that is like your report dataset but only returns distinct values and use this as the query for available parameter values.
For example, if your report dataset is something like this:
SELECT Year, Amount
FROM MyTable
WHERE SomeValue = 1
use the following dataset for your parameter query:
SELECT DISTINCT Year
FROM MyTable
WHERE SomeValue = 1

Related

Conditionally grouping tablix in SSRS reporting

My tablix has following columns
Country, City, College, totalstudent,passedstudent,failedstudent
I have a parameter "GroupBy" with values "country/city/college". So, when i select one of the parameter, my tablix should be grouped by that parameter and only so that parameter column + total,passed,failed columns
For eg. If user selects GroupBy = "City" then, the tablix will show
City, totalstudent, passedstudent, failedstudent
The values in total, passed and failed is total sum grouped in that city.
The similar logic should be applied to country and college also.
So, far i am able to show the all columns with grouping applied by country, then city and then college. (which is one of simple ssrs grouping)
(My need is to only apply the one grouping based on parameter and only show that particular columns)
Note: I have a raw dataset that has all these values retrieved using inline sql from my sql database.
(Dataset1: Country,City,College,totalstudent,passedstudent,failedstudent)
You can group your table by an expression. In your group properties you would write something like this:
=Switch(Parameters!GroupBy.Value = "City", Fields!City.Value
, Parameters!GroupBy.Value = "College", Fields!College.Value
, ...)
The other columns should be able to just use regular Sum functions and work with any grouping.
I tried the different approaches (I went through the last/3rd approach)
Used multiple tablix for the different grouping conditions and used the parameter to hide/show the correct tablix in the report
Pitfall: It is awfully slow since I have 4 different grouping conditions and putting in 4 different tablix.
Using the dynamic grouping concept as illustrated at ( http://www.advancedssrs.com/2014/01/how-can-i-use-dynamic-grouping.html) which is good. But It was not suitable for my situation as it was also comparatively slow while i try to sort the columns in SSRS. (I need the sorting feature in all columns)
Created a new parameter (groupby) which is used to mimic the scenario of tabs. So, when the user selects one of the value ( Country/City/College), I am grouping my SQL result based on this groupby parameter value using conditional grouping statements and returning result back to SSRS.
SELECT
CASE WHEN #GroupBy = 'Country' THEN CountryName
WHEN #GroupBy = 'City' THEN CityName
WHEN #GroupBy = 'College' THEN CollegeName
END AS GroupTitle,
SUM(totals) AS totalstudent,
SUM(passes) AS passedstudent,
SUM(fails) AS failedstudent,
FROM #temp
GROUP BY CASE WHEN #GroupBy = 'Country' THEN CountryName
WHEN #GroupBy = 'City' THEN CityName
WHEN #GroupBy = 'College' THEN CollegeName
END
ORDER BY 1
DROP TABLE #temp
Now, I use the GroupTitle in my first column and rest of the aggregated values in the remaining columns in a single tablix.
The output looks like:
When creating your dataset, don't directly write your query in the box --- instead, use expression.
="SELECT " + Parameters!GroupBy.Value + ", passedstudent, failedstudent
FROM Table GROUP BY " + Parameters!GroupBy.Value
Your "passedstudent" and "failedstudent" will be some aggregation, either COUNT or SUM, depends on your case.

how to group and filter on aggregate in SSRS

I have a requirement to report the number of people who have more than one record in the dataset for my SSRS report and I can't quite get how to filter on the grouping.
So if the dataset results are:
ID PersonID FileID
1 1234 abc
2 7890 ade
3 5647 aer
4 1234 xyz
I would like to report 1. There is one person who has more than 1 record.
Is there an expression or something I can use to do this?
Thank you.
You can use LookupSet and CountDistinct function to get the required count, however you will need the textbox used to show the calculation be in a scope.
If you want to show the number of persons with more than one record as a total in your table use this expression:
=CountDistinct(
IIF(
LookupSet(
Fields!PersonID.Value,Fields!PersonID.Value,
Fields!ID.Value,"DataSetName"
).Length>1,Fields!PersonID.Value,Nothing)
)
Set it outside any group scope:
However if you want to show the number of persons with more than one record outside your tablix in a textbox, you can add an additional tablix and delete the necessary rows and columns to leave only one textbox then set the dataset property to the dataset name you are using and use the same expression.
It should produce:
Note my dataset has more rows to ilustrate the functionality. In the right side there is only one textbox with the count.
Let me know if this helps.
If you want the result to be something like shown below.
Steps:
Create a group on Person ID
Right Click on Group > Add Total > Before
Add a column and put =Count(Fields!PersonID.Value)
If you want to display only Persons having more than one, set the visibility property of the tablix row.

Bind Dropdown in SSRS with all column name of Dataset

I need to bind dropdown in SSRS with all column name of dataset.is this possible to select all column name from dataset in SSRS.please help me....because I am stuck in from last 10 days.
First, create a dataset out of those column names:
SELECT *
FROM [yourschema].INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = [yourtablename]
Then just add a parameter, call it what you like.
Then, for available values, choose to get it from a dataset.

SSRS having multiple dataset Error

I have a Dataset1 which has all records.
I have Dataset2 and Dataset3 for Dropdown filteration.
Dataset1 has a query as follows : select * from vw_shoppinghistory where storename =#storename and city = #city
Dataset2 has a query as follows : Select Distinct StoreName from vw_shoppinghistory
Dataset3 has a query as follows : Select distinct city from vw_shoppinghistory where storename = #storename
On selecting store and then the city should pull the records.
I am facing an error as
" When report contains multiple datasets, field references outside of a data region must be contained within aggregate functions which specify a dataset scope "
You are referencing a field in a dataset on a control that doesn't count as a data region (data regions being things like charts, tables, lists, etc). Most commonly you'll see this on textboxes.
To fix this, you need to do 2 things:
Use an aggregate expression. You can't reference a field outside of a data region without performing aggregation. You can use functions like SUM, FIRST, MIN, MAX, etc.
Specify a dataset when referencing a field. For example, your code that's causing this error is going to look something like this:
=Sum(Fields!city.Value)
What you'll need to do is specify the dataset the field comes from, like:
=Sum(Fields!City.Value, "Dataset1")

how to display total records found in ssrs before view the report

I have created a report that returns results based on my date parameters #startDate and #Enddate. I want to be able to get a result that shows the totals number of records found before actually viewing the report.
How do I add a count function to count totals records found. then add a hyperlink action to open the report?
Here's a suggestion to do this:
Encapsulate the query in a view or stored procedure.
Create a main report what does something like:
SELECT COUNT(*) FROM MyView WHERE myDate BETWEEN #startDate AND #Enddate
Show the First result of your dataset (the count) in a textbox
Set an action to navigate to a subreport (see below) passing the same parameters
Create a subreport with a query like this:
SELECT * FROM MyView WHERE myDate BETWEEN #startDate AND #Enddate
Show a tablix with the data in the subreport.
Optionally include a link back to the main report, etc.