SSRS: Place a calculated row below another row - reporting-services

I can't insert a calculated line (CA) in a specific location between the lines of a category.
I have made a formula where the CA line sums the value of two lines of a category but I would like this line to be placed right after the two other lines from which it has taken the values.
The expression I used for the calculation is :
=SUM(VAL(IIF(Fields!U_Categorie.Value="Ventes de marchandises (en l'etat)" ,Fields!SoldeN.Value,0 )))
+SUM(VAL(IIF(Fields!U_Categorie.Value="Ventes de biens et services produits" ,Fields!SoldeN.Value,0 )))
I would like to add the sum of the two lines and place the new line just below the two lines. Because in this case it will appear at the bottom of the table.

I would almost certainly do this in the dataset query. Append the additional rows to your dataset and add (if required) some ordering logic (a sort order column) to the dataset too. If the CA row needs to be excluded from other calculations you would have to handle that separately.

You can get desired output to create calculated field and use that field in row group.
I Have created sample report, try this below steps and screenshot in your report.
Create Calculated field CA
Add CA as row group
Set row visibility using expression.

Related

SSRS Expression to extract all Names in an Name Field

I have a query that pulls three fields, over 9000 rows (A-Z, names):
I am trying to extract by all "A" name Agencies, "B", and so on into Excel worksheets by each A,B,C,etc., once we render and save the report.
Can someone help with an Expression that will accomplish this?
Thanks,
jer
First create a calculated field in the dataset to get the first letter of each agency.
=Left(Fields!AgencyName.Value, 1)
Next, set up a table (aka tablix or matrix) with two row groups. The parent group should be sorted and grouped by the new FirstLetter column. In this group's properties, set it to break at the end of each group. Also set the PageName property to be the FirstLetter.
The child row group should be grouped by nothing so that it will show every detail row. Sort it by Agency name if desired.
What you should get now is a page for each letter and within each page a row for each agency. When you export to Excel it will create a sheet for each "page" and name them all accordingly.

Display data in single column

I have a table as shown below:
Table 1
I need to display data like below. I have tried using grouping but but i failed.
I have read some topics but can't find the solution. This should not be that hard.
Table 2
You can get that using LookupSet over a dumb group.
Add a tablix to your report and add a parent group in the Row Groups pane.
Use the below expression to create the group.
=1
That expression will create only one group, and you will have something like this in design.
Then use this expression in the highlighted cell in my screenshot above.
=join(
LookupSet(1,1,Fields!ColumnA.Value,"DataSetName")," - ")
Where Fields!ColumnA.Value is the field of X, Y and Z values, and DataSetName should be the name of your dataset.
You will get this result.
If you have repeated values in ColumnA they will appear repeated too in the cell. You will have to filter your dataset to get only unique values.

How to populate a Tablix referencing data from another Tablix dataset?

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

How to Sum the aggregates of a child group

This should be easy, but I am stuck.
I have a table listing some figures about Qualifications - to achieve which a dataset that is essentially a row per Student is being grouped on Qualification with a Parent Grouping on "Measure" (which is just a bucket of qualifications).
One of the columns is trying to work out the number of students (well, more properly the number of students with a value in a particular field, weighted by another field) in each Measure/Qualification. In the screenshot below, it's the "Pred. Avg" column on the right hand side.
So for the Qualification Row Grouping, that column is calculated by:
=CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP")
This works fine - the values of 35 and 11.5 in that rightmost column are correct for those rows. What the top row should be doing is simply adding up the values in the other rows to give me the number of students in this Measure, in this case to give 46.5. To do that the expression I am using is:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP"), "Measure")
However as you can see in the screenshot, this returns 2917 instead.
So my question is; Why doesn't that work, and given that it doesn't work how can I, within a parent group, aggregate the results of aggregates inside a child group?
EDIT:
OK so, I have determined that the following works correctly:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual"), "Measure")
The problem there is that the Qual row that returns 11.5 is weighted to 0.5. I.E. it actually returns 23, and the Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") is for that row returning 0.5 and altering it to 11.5...so the question becomes; "how do I force that ...*Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") into the "Qual" scope, like the CountDistinct() is already in?
The issue here is that you're trying to aggregate values using that Lookup function which only returns one value. There are a couple ways you could go about doing this. One option would be to use the LookupSet function to get the applicable weightings. An even better option is to combine the data in your dataset so that the weighting is available without using a lookup. That way the function can recalculate an any grouping level without you having to force a scope on it. Also, CountDistinct ignores "Nothing" so you can do without the extra IIf statement. Hope that helps.

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.