SSRS Report Builder IIF error with aggregate - reporting-services

I've been struggling with an IIF error when trying to create a variable aggregate.
I'm using Report Builder 3.0
I have a report where users determine what fields are in a report. These fields are passed as a multivalue parameter. I use a lookup from a different dataset to determine its placement in the report, and using the same order dataset to determine if the field is numeric or not (meaning I want to sum the value based on row-level grouping). The headers pull in using the same field lookup, which works fine. At the row level I'm trying to return either the sum of the field value based on row grouping, or if non-numeric, return the value. Based on similar posts I understand that both the true and false parts are processed. I attempted to offset this error by nesting another IIF. If I remove the sum function the data returns non-numeric data fine. However if I include the sum function numeric data is processed fine however non-numeric data returns #error.
What am I missing?
Here is a definition of the data I'm referencing below:
lookupvalue: returns the fields selected by the user based on predefined order in a stored procedure.
Fieldisnumeric: indicates if the field selected is numeric or not, 0 is false, 1 is true
Fielditem: the field item in the tablix being referenced
dtsselectedfields: the dataset I'm looking up the column order and numeric properties of a field.
The number 1 indicates the first position in the variable count of fields selected by the user. Additional fields are hidden based on the count of fields passed in the parameter and are incremental (e.g 1-n).
=iif(Lookup(1, Fields!LookupValue.Value,
Fields!FieldIsNumeric.Value,"dtsSelectedFields")=0,
Fields(Lookup(1, Fields!LookupValue.Value, Fields!FieldItem.Value,
"dtsSelectedFields")).Value,iif(Lookup(1, Fields!LookupValue.Value,
Fields!FieldIsNumeric.Value, "dtsSelectedFields")=0,
Fields!MV.Value,sum(Fields(Lookup(1, Fields!LookupValue.Value,
Fields!FieldItem.Value, "dtsSelectedFields")).Value)))
****edit 12/1/2015****
For additional clarity, I'm providing additional details. Below is 'dtsSelectedFields' dataset.
FieldItem_____LookupValue_____FieldIsNumeric
Item1Desc__________1__________________0
Item1Total__________2__________________1
Item2Desc__________3__________________0
Item2Total__________4__________________1
Let's say I have one column of data, and this column would first look for a LookupValue of 1. This would return the FieldItem, 'Item1Desc'. Because this field is not numeric, I would want to return the value of Item1Desc. However let's assume my first selection was actually 'Item1Total' and I don't want to return the non-numeric Item1Desc field. In this case, because 'FieldIsNumeric'=1 indicating a numeric field, I want to take the sum of this field.
Is it possible to nest an aggregating function in an IIF statement on only one part of an IIF statement? I.e. the true part or false part?
And if so, what am I doing wrong?
An example of the tablix:
sample layout
Column 1 Header____________Column 2 Header___________Column 3 Header
Column 1 Data______________Column 2 Data_____________Column 3 Data
Sample data
Product___________________Country of Origin_________________Units
ABC Envelopes___________________China______________________15
LMN Packets_____________________India_______________________30
In the example above, user selects 3 columns, 'Product', 'Country of Origin', and 'Units'. There are other fields available that would cause multiple rows if I grouped by them in the stored procedure (for example acquisition price). Based on the lookup I return the column description as a header. The row-level detail is described as above (e.g. Return the product name and country of origin, but sum up the units).

As a workaround for my issue above, I found an (ugly?) solution.
As mentioned above, a user can select any number of columns and the report organizes them in columns based on a predefined order according to a stored procedure. (E.g. a product description would come before the sum of the units if those two columns were chosen, but a product ID may come before the product description, but only if the ID was chosen.)
For every possible number of columns a user can select, I added two columns in the report (i.e. two for each field).
The first two columns will reference the lookupvalue=1. I then set the expression of each field in the detail to 1) a sum of the value, or 2) the value itself. I then set the column visibility to the results of the 'FieldIsNumeric' column. So the summed numeric column which would return an error for non-numeric data would be hidden when FieldIsNumeric=0, and the non-numeric column referencing the lookup value =1 would be shown, and vice versa.
Needless to say additional columns would follow the same logic in sets of two, each referencing the sequential lookup value (e.g. columns 3 and 4 would reference lookupvalue=2, columns 5 and 6 would reference lookupvalue=3, and so forth. Each column within the matching pair would be displayed or hidden based on the returned value of FieldIsNumeric in the same lookup dataset.
I'm definitely open to suggestions, but thought I'd post this as a workaround solution.

Related

Expression to calculate % in a report

I am building a report(report server project) using the Data Tools. I have a column Quantity it has a Total.
I need another column that calculate the share(%) of each line in the Quantity comparing to the Total.
The expression would be: Line_1_Share = Quantity_of_line_1/Total.
I tried =[Sum(Total/Quantity)] but it does not even accept as a valid expression.
If you right-click the textboxes that contain your working 'Quantity' and 'Total' values and look at the expressions you will see the correct format.
For exmaple your 'Quantity' expression might be something like
=Fields!Quantity.Value
or if it is in a grouped row it might be
=SUM(Fields!Quantity.Value)
your 'Total' expression might also be
=SUM(Fields!Quantity.Value)
When you use SUM() (or any similar aggregate) then the scope of the expression decides what is included in the sum. The scope can be a single row, a row group or an entire dataset. If you do not specify a scope then the position of the textbox determines the scope.
So, if you have a simple table with no grouping other than the total line and your dataset name is dataset1 then your expression would need to be
=Fields!Quantity.Value / SUM(Fields!Quantity.Value, "dataset1")
The above reads .... "For the current row, take the Quantity and divide is but the sum of all Quantities that are within the entire dataset called dataset1"
If this does not help, post your current report design including and row and/or column groups.

Row suppression based on multiple independent conditions

I have a row group that I need to suppress visibility based on multiple independent conditions. One condition is based on if my grouping field equals one value and the other is based on value returned on a summation expression if a separate field contains a unique identifier. So for Example I am grouping my data on a field name Level 03 if level 3 is equal to cash and my index is greater than zero the cash data point should be excluded. But I also want it to look to another field in the my report table and if that field is equal to a particular identifier (test) then I want it to complete a summation test and suppress the filed is the value of the summation is zero or less than zero.
When I right the expression as =iif(Fields!Level3.Value="Cash",True,iif(Fields!Level3.Value.indexof("Receivable")>0,True, False)) the suppression works and the Cash component is excluded.
However, when I add the next condition the row is still visible with although the all conditions are met/true. I was using this expression:
=iif(Fields!Level3.Value="Cash",True,iif(Fields!Level3.Value.indexof("Receivable")>0,True, False)) AND iif(Fields!Identifier_Code.Value="Test",True, iif(sum(Fields!Year_One.Value<=0 and sum(Fields!Year_two.Value<=0, True, False))
I get an error message that says The visibility Hidden expression for the tablix "Assets" has a scope parameter that is not valid for an aggregate funtion. 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."

How can I create an expression in an SSRS report similar to an Excel formula?

I need to combine the results of multiple similar Stored Procedures into a single Tablix.
I'm using multiple Stored Procedures that return the same data, but for varying Units. So in one "cell" (I don't know if that is the correct terminology for a data field in a Tablix) I have an Expression like so:
=IIF((Fields!Week.Value="WK1"),Fields!Price.Value,"")
...which conditionally displays data when the value of the "Week" field is "WK1" and the Stored Procedure for a Unit value of "BARNEY" is the dataset.
After that (on the same row, in a column to the right in the Tablix) I need to show the same data from a different Stored Procedure where the Unit value being used is "RUBBLE". I need the Expression to reference an existing value (ItemCode) in the Tablix from the first Stored Procedure, so that both cells on the row are displaying values for the same ItemCode (but different Units).
That cell/field is a simple pointer to the ItemCode value returned from the Stored Procedure:
=Fields!ItemCode.Value
How can I use a formula to display the data for the ItemCode that the initial Stored Procedure is displaying data for on that row. Something like this:
=IIF((Fields!Week.Value="WK1" AND Fields.ItemCode=[Existing Item Code value in this row]),Fields!Price.Value,"")
?
IOW, what do I need in place of the "Existing Item Code value in this row" to make this work? Could it be something like this:
=IIF((Fields!Week.Value="WK1" AND Fields.ItemCode=TextboxItemCodeData.Value),Fields!Price.Value,"")
?
If the main dataset for the tablix you are working in is BARNEY, then this is the basic lookup expression that you should start with to get data from the RUBBLE dataset.
=Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Price.Value, "RUBBLE")
In this situation, the Price will be returned when the ItemCode values match between the BARNEY and RUBBLE datasets.
This is the expression that may help you hide or show a value from the secondary dataset.
=IIf(Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Week.Value, "RUBBLE")="WK1", Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Price.Value, "RUBBLE"), "")
The first part of the IIf is checking the Week field in the RUBBLE dataset. If the value is WK1, then it displays the Price from the RUBBLE dataset; otherwise nothing.
This might work if you don't have to check the Week value in the RUBBLE data, and just checking in the BARNEY dataset will work.
=IIf((Fields!Week.Value="WK1"),Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Price.Value, "RUBBLE"),"")

SSRS LookupSet returns only one kind of value

I'm designing a report in Report Builder 3.0.
Here is my sample dataset.
The column Event_ActivityName contains two distinct values.
I'm trying to get a comma seperated list of all values from this column using LookupSet with this expression:
=Join(LookupSet(Fields!Event_ActivityName.Value, Fields!Event_ActivityName.Value, Fields!Event_ActivityName.Value, "Main"),",")
(Where Main is the name of the dataset in Report Builder).
Unfortunately, the result of this expression is a comma seperated list of the value which shows first in the column times the number of times it appears in the column.
In other words, my column contains two distinct values, but my expression only returns one of them. How do I make it return both?
LookupSet compares a source expression to a destination expression, then returns a result expression when they match. In this case, you are asking LookupSet to find the Event_ActivityName in scope and bring back all instances of it (which is why you only get back one value times the number of occurrences in the set).
To get all values from this column, use source and destination expressions that will always be equal, like:
=Join(LookupSet(1, 1, Fields!Event_ActivityName.Value, "Main"),",")

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.