How to populate a Tablix referencing data from another Tablix dataset? - reporting-services

I have two Tablix: Tablix A and Tablix B:
Each Tablix is connected to different datasets as illustrated in the image below:
How do I populate Tablix B by looking up data in Tablix A?
For example: Tablix A contains Vehicle models but I also need to populate Tablix B with Vehicle colors using the VehicleID in both dataset.
Using a Lookup Function, this only works if both datasets are references in the same tablix, how do I do this using separate tablix?
Attempting to use separate tablix, I get the below error:
[rsFieldReference] The Value expression for the text box
‘Textbox57’ refers to the field ‘VehicleColor’.
Report item expressions can only refer to fields within the current dataset scope or,
if inside an aggregate, the specified dataset scope.
Letters in the names of fields must use the correct case.
Illustration:

You can use "lookup" to get a single value from another dataset. For example:
=Lookup(Fields!VehicleID.Value, Fields!VehicleID.Value, Fields!VehicleColour.Value, "Vehicles")
would bring out a single (the first in the dataset) VehicleColour where the IDs matched. If there is only a single match of ID between the two datasets, then the correct colour would be returned.
=LookupSet(Fields!VehicleID.Value, Fields!VehicleID.Value, Fields!VehicleColour.Value, "Vehicles")
brings out an array, which can only be displayed in a textbox if it's converted into a string using join:
=join(LookupSet(Fields!VehicleID.Value, Fields!VehicleID.Value, Fields!VehicleColour.Value, "Vehicles"), ", ")
which will bring out a comma separated list of all VehicleColours where the IDs match.
For more information on Lookup, see: https://msdn.microsoft.com/en-GB/library/ee210531.aspx
For more information on Lookupset, see: https://msdn.microsoft.com/en-us/library/ee240819.aspx

Related

SSRS Report Builder IIF error with aggregate

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.

Applying different Visibility to each Tablix

I have a report showing hours and dollars that are written off. Jobs for this report are classified as NRB (non-billable) and non-NRB (billable). Each job type has its own Tablix in the report and I want to populate each Tablix based on a bit value - IsNRB.
All of the "0" IsNRB rows should populate the top Tablix and the "1" values should populate the bottom Tablix . For the most part this is working. What is happening, however, is that some Programs or Clients will have both NRB and non-NRB jobs, and it appears that as each Tablix works its way through the rows of the report dataset, it will capture and retain the first value for IsNRB and apply that to the entire report.
I have tried logic similar to the following in a number of places/ways:
=IIF(Fields!IsNRB.Value = False, Fields!CustProgram.Value, NOTHING)
The Grouping hierarchy of the report looks like this:
ProgramGroup
ClientGroup
Job/SubJobGroup
Detail is here
I have tried setting evaluative expressions similar to the one above on TablixVisibility, GroupVisibility, RowVisibility, and in the field expression itself. The behavior seems consistent in that the first row for that Program, Client, or Job sets the value of IsNRB for the entire report.
As a concrete example, the first Program, "Cascadia" has three rows where IsNRB = 1/True and two where IsNRB = 0/False, and the latter two rows of data are always misapplied because the value of 1/True is overriding the 0/False valued rows.
What is the proper approach to take that will allow the first Tablix to accept and display rows of data where IsNRB = 0 and the second Tablix to show those with a value of 1? Do I need to abandon the IsNRB bit datatype and just have a distinct dataset for each Tablix? That seems like a klunky way to approach the report.
Filter each table on the IsNRB field. Right click the tablix and select Tablix Properties. Select filter, then then select the field you want to filter against (IsNRB) and the value your want it to be (1).
This will put all records with a 1 for the field in one table, and with a 0 in the other

"lookup" function of RDLC report isn't work in this case

I have three related three dataset like these
I need to display "INVOICE_CODE" from DatasetA concatenate with "COUNTRY_NAME" from DatasetC Example :
"INV123-Korea"
I tried to use "Lookup" function by this step
1.) First table is used for main table in a report.
So I will assign DatasetA to my tablix1
2.) At Tablix1, rigth click on a cell and create expression via
3.) Put this concept code. (A--->B--->C)
=Lookup(A.FK,B.PK, Lookup(C.FK,B.PK,C.ANS,"Dataset C") , "Dataset C")
But It's not work.
In this case using Lookup function is not my first preference but if you want to accomplish using lookup you can do something like this.
=Lookup(
Lookup(Fields!Customer_Code.Value,
Fields!Customer_Code.Value,
Fields!Country_Code.Value,
"Dataset B"),
Fields!Country_Code.Value,
Fields!Country_Name.Value,
"Dataset C")
Note: SSRS is case sensitive so make sure you are using correct casing for your fields and Dataset names.
Lookup function returns only the matching value for the dataset you referenced. There is another SSRS function LookupSet which can be used to return the set of matching values based on name/value pair.
First lookup you get Country_Code from DataSet B by supplying the customer_Code value from the Dataset A.
Second Lookup function will use the result of first lookup function to get the Country_Name from the DataSet C.
To show both Invoice from Dataset A and Country_Code from DataSet C. Create two placeholders. In the first placeholder directly put =Fields!Invoice.Value and in the second place holder ut the above lookup expression.

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 lookupset - row output

I am looking to use the lookupset function. I have a one to many relationship when one Risk has many Actions.
Using this function I can return it as a comma separated line, however what I really need is for each entry to display in a new row of a table, is this possible?
I have replaced the comma so instead of creating a comma separated line it does a newline, however I need it to line up with other values. This Is why I would like to to come out in rows in a table.
Can it display on separate lines rather than separate rows? If so, then you can simply separate the fields using carriage return/line feed pairs, like so:
=Join(LookupSet(Fields!Id.Value, Fields!Id.Value, Fields!FieldToLookup.Value, "LookupDataset"), vbCrLf)
Otherwise you are better off defining a subreport and embedding that in your table. The subreport is simply a report that is just a table with the report taking a parameter. You add this to the table in the main report using the toolbar and then set the parameters in the subreport properties to pass in the identification field name from the table's dataset.