Dynamic groupings using IIF with multiple datasources - reporting-services

I'm using report viewer and trying to create dynamic groupings on my table. Before the report is generated, I have a popup that ask if the report generated should be grouped by category or not.
I have two datasets, one called ReportParameterDTO and the second is called LoanDTO
The tablix is connected to the dataset LoanDTO. I want to create a parent grouping expression for that tablix such that if the first value of ReportParameterDTO.GroupByCategory is true, then it should group, otherwise do nothing.
What I tried
=IIF(First(Fields!GroupByCategory.Value, "ReportParameterDTO") = true, Fields!Category.Value, ""))
It gives me back and error around Fields!GroupByCategory.Value and the error within the error list states that A group expression for tablix includes an aggregate function.
The IIF Expression will compile if I use Field Values from LoanDTO but I don't want to do that.

Add a new parameter.
Set it to Internal.
Set the Available Values to pull from the ReportParameterDTO dataset and the Value field will be GroupByCategory.
Also set the Default Values to pull from the ReportParameterDTO query.
Now you can refer to this internal parameter in your grouping expression like so:
=IIf(Parameters!GroupByCategory.Value = True, Fields!Category.Value, Nothing)

You can create both table and whit your parameter show or hide the table visibility. So like this I think is going to be more easy for you to set up your table and groups.

Related

Microsoft Report Builder: How to display selected chosen values from a multi-value parameter in a table?

I'm using MS Report Builder v3.0 to create a report. As part of this report, I have a multi-valued parameter (named #Diagnoses). The labels and some of the values (truncated by the size of the display boxes) of this parameter are shown below:
What I would like to be able to do is display the labels / values the user chooses in a 2-column tablix (I've tried using separate textboxes for the labels / values but the results are mis-aligned).
However, this does not appear to be straightforward. The closest method I've found is this one, which stores the user's choices in an internal parameter in xml format, then queries this parameter to produce a dataset from the xml.
So, I created the xml-producing internal parameter like this:
...and I've created a dataset based on this data, with the following query:
But now when I put these values into a tablix, the labels and values are now on separate rows, like this:
Does anyone have a straightforward way of sorting this out?
Best Wishes
C J
OK - I've solved it (it's not pretty, but it works!)
Basically, the problem comes from having to use the join statement when creating the xml - you can't really put both the label information and the value information on the same row in the xml.
To get round this, you have to use two internal parameters to create two datasets - one for the labels column, one for the values column. The method for creating these is essentially the same as that shown above, except for the values parameter, the expression for the default value is:
...and for the labels parameter, it's this:
(by the way, make sure you set the available values to "None" for internal / hidden parameters - the expressions here are for the default values)
Then, when you create the values dataset, you use the following syntax in its query:
...and similarly for the labels dataset.
Finally, in the report, you create one matrix from each of the two datasets, then put them next to each other, using fixed row heights and setting "can shrink" / "can grow" to false so that they look like they're in the same table:
I hope this helps somebody!

SSRS: Toggle Report via a parameter

I'm creating a single SSRS report that is composed of data drawn from different Datasets. What I'm wanting to do is have a drop down menu where the user selects the dataset they wish and have the appropriate table turn on and show them the dataset information.
Right now I'm testing with two tables and in there Visibility property I have the following expression:
=IIf(Parameters!AppSelection.Value = "STRAW", false, true)
The other table has the exact same line in the same place but with a different value between the quotes.
With my parameter, I created a new one and called it AppSelection and gave it 2 Available Values that matched the words between the quotes in my above expression. The data type for my parameter is Text and the Value of the each Available Value is left at null.
When I preview my report and select the different values in the parameter, nothing happens. What is it I'm doing wrong?
Change the null in the available values to your text, ie STRAW.
You may find that the tables show the other way round from expected, switch the true and false.

SSRS Visibility Hide iif All

Just wondering if it is possible to do the following on SSRS for a textbox visibility (hide), it seems to return an error for me:
=iif(parameters!category.value = "All",True,False)
I have a long list of category so therefore is impossible to list them all, is it possible to the above? I keep getting an error with the above-outlined syntax
I assume the category parameter is multi-select with available values fed by a SQL query. You can use the Count property on the parameter to get the number of selected items and compare that to the number of items returned by the SQL query using the COUNT() SSRS aggregate function with a scope of the dataset. If the number of selected items matches the number of available values then they must be all selected.
So your code would look like:
=IIF(Parameters!category.Count = COUNT(Fields!CategoryName.Value, "CategoryParameterDataSetName"), True, False)
In this case the dataset that contains all of your available values is named CategoryParameterDataSetName and contains a field named CategoryName. Change these values as appropriate.

SSRS expression issue using iif function

I have a data set that is returning two properties, a name and a total units. I am trying to set an iif expression on a data bar where iif(field!Name.Value = "Name", field!Total.Value, 0)
this is not working I get an error of rsFieldReferanceAmbiguous, the fields refers without specifying a dataset aggregate. And the only option that it gives me as an aggregation is First, but I do not want to get the first name, I want the bar to display the total units base on the name field that is in the iif expression.
rsFieldReferenceAmbiguous refers to trying to match something that is not in local scope. Therefore you have to aggregate it. You are probably wanting something like this:
=Sum(IIF(Fields!Name.Value = "Name", Fields!Total.Value, 0))
The function you are trying to use would be better suited to a calculated field in your dataset. Then you can just refer that that field in your report. This allows you to filter the data line by line instead of by groups.
Right-click on the dataset and go to Dataset Properties.
Go to Fields.
Click Add then Calculated Fields.
Enter the name of the field and then the expression here.
Make sure your tablix has the dataset specified under General -> DataSetName on the properties pane. If you have more than one data set on the report you will need to specify which data set your reffering to like so:
(Fields!Name.Value, "NameDataSet")
If your useing tables you may need to ckeck if you have grouping and if so how your grouping your data.

Sending multiple values in ssrs parameter to subreport

Currently have three subreports, one main report.
Main report has two parameters - SELECTDATE and EMP_ID. Main report sends Order_Nbr to all subreports.
All subreports work perfectly when I only select 1 Employee and 1 date, but if I choose multiple values it blows up.
SQL has the column as an INT. I have both parameters in main report and subreport, SELECTDATE is set as Text with Multiple Values, and EMP_ID is set to Integer with Multiple Values. My queries has my date IN (#SELECTDATE) and emp_id IN (#EMP_ID).
It obviously sends the correct information to the subreports because it works, but I would like it to work with more values being passed. Love the current ability to check and uncheck employees and end of month dates, like it currently is set using the IN function in my query.
Make the Parameters on your sub report non-multivalue, remove any 'Available values' set.
Pass the multivalue parameter from you parent report as a string using the join method
=Join(Parameters!Emp_ID,",")
The EMP_ID parameter will be set to a comma delimited list, which is what a multivalue parameter sends to the query
I'm not sure how this works with text queries, but it works with stored procedures.
If the sub report is also used as a stand alone report you will need to add a new parameter to allow the user to send parameter values to #Emp_Id from a parameter the user can set
I guess you have not set the parameter in the sub report as Multi Select. If you have set the parameter in the sub report as multi select, then you could just send the parameter from the main report to the sub report as it is. See more at here
I used the following solution, which works in SSRS2016. This also works with text parameters.
Like suggested above, pass the parameter as a string to the subreport by JOINing the values.
Join(Parameters!EmpID, ",")
In your subreport, accept the parameter as text.
In the SQL of your subreport, use the string_split function of SQL 2016 to return a table of the values and simply join it to your main query. So basically if your parameter is named "EmpID_Multi" do
... JOIN (SELECT value FROM string_split ( #EmpID_Multi, ",")) mv ON mv.value= ...
Note: You might consider pulling the values into a temporary table for SQL optimization (sometimes the optimizer does funny things...).