SSRS 2005 Divide values of two text boxes - reporting-services

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.

Related

SSRS Manually select values passed to a multi-value subreport parameter

In SSRS, I have a summary report, and when I click on any figures, it drills through a subreport that generate a list of skus.
I have setup the cells in the summary report and selected all Parameter for the drill through report.
For a multi-value parameter in the subreport, I want to manually select 2 out of 3 available values.
In the textbox property, under Action and parameters, What is the expression to specify the values I want to pass to my subreport?
1,2 - If your parameter is a integer. Don't use the expression with an equals sign, just 1,2 in the parameter value.
If your parameter is a string, I believe you need to double the double quotes.
""1"",""2""
You could also use the SPLIT function to create a string array from the hard-coded values:
=Split("1,2", ",")
Neither formula worked, but at the end, I just modified the list of available value on the subreport and added another value. Then, in the dataset query, I adjusted the WHERE clause so that when the paramater has said value, the field IN ("1","2")

SSRS expressions SUM between textbox

I'm trying to calculate an expression to SUM two ssrs textboxes but then I get the following error:
The Value expression for the textrun ‘Textbox343.Paragraphs[0].TextRuns[0]’ contains an error: [BC30456] 'textbox346' is not a member of 'Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.ReportItems'.
The error message says that the control textbox346 can't be found. As you say that you try to calculate a SUM on this textbox, you probably want to do this in a group header or footer, but on that level, you can't access a report item (a textbox) on a lower level (a details row), because there can be many of them.
Also: Aggregate functions (like SUM) can't operate on expressions that refer to report items. The values in such expressions must depend just on the dataset. The amount of data can be controlled by grouping the tablix and using a scope for the function.
Therefore, if your textbox textbox346 (on the group details level) is bound to an expressions depending on just dataset fields, use that same expression in your SUM furmula in Textbox343 (in the group header or footer).
could you just sum it in sql? it's often easier to just avoid the error by summing it up in the dataset.

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.

SSRS Summing Group Variables outside of the group

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