SSRS - Toggle subreports by parameter value - reporting-services

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.

Related

List report, filter by letter

I am building a summary report which looks at users that are marked in a database as having a common trait i.e return all users by name in the last 5 years whose contract contains an end date.
This generates a figure e.g. [250]
I drill through on that figure to give a list report of names, first name and surname.
I have ordered the list A-Z
I would like to add a row of 26 letters at the top of the report and have each letter return only the names with the corresponding starting letter.
Would this need to be a further drill through or is it possible to refresh the existing list based on a user-driven selection?
Just add a custom parameter to your report. Right click on Parameters and Add Parameter.
(and so on...). Default value should be All then.
Then simply add the following filter to your tablix:
'Expression:
=Switch(Parameters!YourParameterName.Value = "All", True, Parameters!YourParameterName = Left(Fields!YourNameField.Value, 1), True)
If you are just using SSRS as it comes, then you can't refresh report content without running the report again, so you would either
re-organise your current report.
need another drill through report.
Depending on your layout you could group the data by the first letter and then have an collapsible row group to show/hide that group of names. To do this simply add a parent row group, set the value, group value and sort value all to =LEFT(Fields!myNameField.Value). Next set the visibility of the details row group to hidden and set the toggle visibility property to point to the cell that contains the letter from the parent group you just created.
If you have too much data to make this efficient the you might have to go down the additional subreport route.
To make life a bit easier, and to save you having to create 26 links and parameter values, I would do the following...
Create a table that stores the list of letters
Add a matrix to your report, that has a column group grouped on the letter value from this table. This will act as your 'filter bar'
Set action on the matrix cell to "go to report", point to the final drill thru report and pass the [myLetterColumn] value as the parameter.
There's no need to set available parameters assuming this sub-report will be hidden and only called from the parent report.

SSRS report pass multiple VALUES to drill through report parameter

I created a report with 5 fields in a hierarchical order:
Order Date
Time of Day (AM/PM)
Parent Name (aka customer)
Product Line
BIC Part Number (aka Item)
Each field expands down to the next level, so order date expands to time of day, etc.
I want to create a drill through report so that the user can click on each level of the hierarchy and see the detail.
This works fine at the lowest level - Item - because only 1 values from each field has to be passed to the drill through report parameter. However, when I try, for example, to drill through based on Product Line, there will usually be 3 or 4 Items within this product line. In the Go To action, I have the drill through parameter "bic_part" set to the main report FIELD value "BIC Part Number".
I have the tablix on the drill through report set where "BIC Part Number" IN [#bic_part].
I just want to be clear, I am passing a set of report field values to the drill through report parameter, not parameter to parameter.
I have tried using expressions with =Split(Join(field value),","),",") and all variations on that. I can't seem to get the child report filters to accept multiple values from the BIC Part Number field from the parent report.
I also tried omitting the BIC Part Number value in the go to report section, but it would not let me.
All of the parameters in the child report are set to accept multiple values. My data source for both reports is the same stored proc, so I can add a query filter. I would appreciate any help.
I think each sub report link needs to be slightly different.
In the subreport, each parameter needs to accept null and your query needs to look for
(FieldName = #FieldNameParameter or #FieldNameParameter is null)
This will allow you to pass the lowest possible solid value, then null for all child values.
If we're looking at the Parent_Number level, on that subreport link you would pass Fields!Parent_Number.Value and then Nothing for each of the lower parameters (Product_Line, BIC_Part_Number).
This will allow you to filter on the lower common denominator in your sub report - Part_Number for this link, Product_Line for the next one down, etc.
I've used this logic in reports before, so it does work. Let me know if my explanation needs clarification - it's Friday afternoon..

In SSRS is there a way to make a Row Group expand based on parameter value?

I've got a table with 5 columns, the first 3 of which allow the user to drill down through the levels of detail. Each of these columns (Region, Country & Office) has an associated Parameter so the user can select the geographic region for their report. Each parameter allows the selection of multiple values.
If the user selects 1 Region, 1 Country and 1 Office it's not exactly ideal for them to then have to expand each selection. Is there an expression I can enter somewhere to state that if only 1 value is entered in a parameter then that data set will automatically show as expanded?
This is in SSRS 2008 R2 if that makes any difference.
In the Group Properties for the detail group you can enter an expression for the initial visibility. Right now you probably have that set to "Hide." The expression needs to return a Boolean and could be something like:
=Parameters!Country.Count <> 1
This will have SSRS hide those rows if more (or less) than one value are selected in the parameter Country
But I have seen some unexpected results with this: test thoroughly. In my experience, BIDS handles these better than SSRS itself, so just when you think you've got it all working, it fails miserably once deployed. (Reason number 14 to have a test folder on production SSRS.)

SSRS. Hide a Column based on Row Group Value

My application uses SSRS to produce payslips for employees. The Payslip report consists of a tablix with 5 columns. Among the 5, is a column called "Units" and another called "Invoice value".
The report has several Row Grouping levels, but the only important one for this question is the Payslip Number Row Grouping "RG_SlipNum". There is a page break after each "RG_SlipNum" RowGroup.
When users want to print Payslips, they can optionally supply up to 5 parameters which filter the result set to print out.
Employees can be paid based on the number of units delivered * a rate (Unit Based), or by a percentage of the invoice value (Invoice based) for the delivery (Oversimplified, but hopefully, you get my drift).
If the employee is Unit based I want the Units Column to Show, and the "Invoice Value" Column to be hidden. If they are Invoice based I want both columns to show.
My dataset has a bit field indicating whether to show or hide a column based on the logic above. It will be a 1 or a 0 for every underlying row within the current rowGroup. I have tried to use the First(,) function in a Column Visibility expression on the "Invoice Value" Column. However, I get the following error whenever I try to limit the scope of the First Function to the current Payslip Rowgroup using the RowGroup name.
"The Hidden expression for the tablix 'X' has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset. "
So, my Question(s)
Can you define a RowGroup name as the Scope argument in a First() function?
If not, What's the best way of achieving this without completely re-working my Dataset / RDL to accomplish this. (Using SSRS2008)
Why is it always just after posting a forum question, you figure it (or some workaround) out?
I'd still like some (better) answers if anyone sees this, but I've set a cell in the tablix to the value of the bit field that determines whether to show the column or not. I then changed my Column Visibility expression to check the cell value (using ReportItems!textboxname.Value) and it's working. as I scroll the payslips the columns visibility changes appropriately.

SSRS Multi Value Parameter. Check whether "Select All" is selected

I have a multi value parameter in my SSRS Report. I want to find out whether (Select All) is checked in that parameter.
In other words, whether all the values in the parameter are checked or only some values are checked.
Is it possible?
I am able to find out number of selected values through Parameters!Parameter.Count. Is there a way to find out total of items in that parameter?
In case anyone is still having issues doing this, I just coded this easy fix.
=IIF(COUNTROWS("dataset").Equals(Parameters!parameter.Count),"it is equal","this is not equal")
For the specific use-case of showing the selected filter on your report in a textbox, here's the expression that will show "All" if "(Select All)" is selected, otherwise it will show all the selected values as a comma-separated list:
=IIF(
Parameters!YourMultivalueParam.Count = countrows("YourDataset"),
"All",
Join(Parameters!YourMultivalueParam.Label,", ")
)
(split onto multiple lines for readability)
countrows reference: https://technet.microsoft.com/en-us/library/dd255215.aspx
Credit to other answers, just want to extend them for this common scenario.
Your approach sounds good: I would make the options for the parameter come from a dataset.
Then you can use =COUNTROWS("DataSetName") to return the total number of options for your parameter and compare this with Parameters!*Parameter*.Count as you suggest.
I also faced this problem and I solved it this way.
I have one multivalued parameter named "Carrier". Then I have added one parameter "CarrierHidden" which is same as "Carrier" only thing is I made its Visibility as Hidden.
="Carrier=" & Switch(Parameters!CarrierHidden.Count = Parameters!Carrier.Count, "All",
Parameters!Carrier.Count > 1 And Parameters!CarrierHidden.Count > Parameters!Carrier.Count, "Multi",
Parameters!Carrier.Count = 1, Parameters!Carrier.Label(0))
The easy way will be to count the number of the selected parameters and compare them to the dataset
=IIF(Parameters!company_number.Count = CountRows("Dataset1"), True, False)
The problem is if you're trying to pull something for another data set then cross referencing the row count in another dataset won't work. You will have to go with what the previous post states. Create an internal parameter of the exact type and assign the default value to the entire dataset. That way you have the max count of the rows since the hidden parameter.count = rowscount. That way you can use it within another dataset also provided that dataset is AFTER the first one is populated.
According to Microsoft's SSRS help search:
=Parameters!<ParameterName>.Count
Returns the integer value 1. For a single-value parameter, the count is always 1.
I verified this does indeed work, check the integer returned for the built-in parameter count field.
Allow multiple values on a parameter selection. Checking the value of the above field will let you know how many values the user actually chose.
In my situation, I allow multiple values on company number. This gives users the ability to choose one company to report on or several at once. Per client request, if they choose more than one, display data horizontally. If only one company is chosen in the parameter list, show the data vertically and hide the other tablix.
So my visibility show or hide expression looks like this in the one tablix:
=IIF(Parameters!company_number.Count > 1, True, False)
and like this in the other:
=IIF(Parameters!company_number.Count = 1,True,False)