SSRS Summing Group Variables outside of the group - reporting-services

I have succeeded in building a number of group variables within an SSRS report, however what I want to do now is to use that variable outside of the group.
eg - I have a variable that calculates a payment within one dataset, and another one that calculates a payment within another dataset.
The first would be =Variables!QualityPayment.Value, the second would be =Variables!RevenuePayment.Value. Revenue and Quality are displayed in different SSRS tables.
I want to add the Quality Payment and Revenue Payment together, but when I try and put them outside of the table I get the error message
'Expressions can only refer to a Variable declared within the same grouping scope, a containing grouping scope, or those declared on the report.'
How do I go about adding the two together?
Thanks in advance
Jon

What I would do would be to use the group variable just as a way to add the values to an external variable, declared on the VB Code section of the report:
On the Report Properties -> Code section you use the following code:
Dim variable1 AS Integer
Function addValue(ByVal value AS Integer)
variable1 += value
End Function
Function getValue()
return variable1
End Function
Then on the group variable section of the tablix, you just call addValue(somefield) and when you need to access the calculated value you can do it from outside the group by calling the getValue function.

Assuming that both datasets are accessing the same database, I suggest combining the two datasets into a single dataset.

In your definition of the variables, make sure that any aggregate functions have the dataset specified for the scope, i.e.:
=SUM(Fields!MyFieldName.Value, "DataSet1") / 12

Related

Using a parameter as a filter - Multiple values not working

The report works for just 1 choice, but when I add more than one, it does not return anything ( no errors, just nothing in the report).
My SQL statement includes the parameter #Region
where Region_Name IN (#Region)
In the Region parameter's properties, I set to allow multiple values.
in the dataset filter's properties:
Expression: =Fields!Region.Value
Operator: IN
Value: =Parameters!Region.Value(0)
*EDIT
I removed the dataset filter as suggested.
Below are the properties for the parameter.
The available values come from another data set that is a distinct list of regions.
Your edit makes a lot more sense. To use multivalue parameters you just need to reference the parameter in the usual way, except use in within the SQL:
select cols
from table
where specificcol in #Region
And then don't have a dataset filter set, just make sure there is a reference to the Region parameter in the Parameters property page. The filtering of the data is handled by the inclusion of the parameter in the SQL, so you don't need to also have a filter on the SSRS dataset.
Instead of using a parameter to go back and forth between the stored procedure and the report, I created the parameter and used it in the tablix properties.
Expression: =Fields!Region.Value
Operator: IN
Value: =Parameters!Region.Value
When you first create the value, it adds a (0) to the end of the expression. Remove that and it works as expected.
Thank you #iamdave for the help!
EDIT:
I came back to this and was able to filter using the parameter and stored procedure.
I followed a link from a question to here: http://www.codeulike.com/2012/03/ssrs-multi-value-parameters-with-less.html
I created a dataset parameter and removed the one from the tablix properties. Then created the function provided and it worked. I did not mess with the "ALL" features in the post.
Thanks for all the tips. Brent

Dynamic groupings using IIF with multiple datasources

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.

Multiple values to pass in a subreport SSRS

Can I use the below expression to pass multiple value in a parameter in subreport?
=Join(LookupSet(1,1,Fields!Name.Value, "DatasetName")," / ")
Will the Join and LookupSet function work in prameter value expression?
No your expression won't work. The Available Values for the Parameter are expecting a single record at a time.
I would create a parameter in the main report with the dataset as DatasetName with the Value of Name. You can set that to Hidden and don't need to use it.
Use that parameter to link to your sub report's parameter.
That should have the same functionality as what you want and would be faster that using the JOIN/LOOKUPSET.
As long as the receiving parameter in the subreport is set to "allow multiple values", you should be able to pass in the lookupset array itself without needing the JOIN function at all.

ProperCase SSRS 2008 Within Footer

I am trying to create a footer that is using ProperCase within SSRS 2008
I have tried
=Code.ProperCase(LCase(Fields!aField1.Value, "DataSet1"))
to use the ProperCase field within the footer but it is stating that I do not have the text box linked to a DataSet.
Help would be much appreciated.
I don't think the problem lies with the ProperCase function. However, when inserting a value from a dataset, outside the context of the dataset, you must specify what record to use. For example, to use the first record from the dataset in your page footer, you should write your expression like this:
=Code.ProperCase(LCase(First(Fields!aField1.Value, "DataSet1")))
In other words, the reference to "DataSet1" makes no sense in the LCase-function, which is just a simple string manipulation function. To reference the dataset, you must use one of the Aggregate functions (in this case, First()), which takes as second argument the name of the dataset in question.
I assume you have written the ProperCase function yourself? There is a VBA function available in SSRS that allows you to change the case of a string and it's called StrConv which you could've used.
In your case you'd write: StrConv(First(Fields!aField1.Value, "DataSet1"), vbStrConv.ProperCase)
The other benefit of the StrConv function is that you can specify a localeID too if that is of any relevance.

SSRS 2005 Divide values of two text boxes

I thought this would be simple, but i must be missing something
here is my expression
=Sum(ReportItems!ID.Value)/Sum(ReportItems!NumberofUnits.Value)
I get this error.
The Value expression for the textbox 'textbox14' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers.
I really just want to divide those two report item values.
You cannot use an aggregate function (SUM) on a ReportItem. remember that a ReportItem is a textbox or other object inside the report. So either change your expression to:
ReportItems!ID.Value/ReportItems!NumberofUnits.Value
Or in case your ID and NumberofUnits reportitems are inside the context of a dataset (for example, in a tablix), and both of them corresponds to fields in the dataset, do this:
Sum(Fields!ID.Value)/Sum(Fields!NumberofUnits.Value)
You may optionally specify the scope over which the SUM function should work, by adding the name of the scope (for example dataset name, tablix name, group name) as a 2nd argument to the SUM function.