Get Sum of Data from Second Dataset in the Second Tablix of SSRS report with Report Builder - sql

I have two different dataset which has a common value placed in two different Tablix in Report Builder tool. I want to achieve a SUM of ELEC_DATA in the second Tablix.
I have already tried using this expression.
=LOOKUP(Field!COMP_ID.value,Field!COMP_ID.value,Field!ELEC_DATA.value,"DATASET2")
The result shows nothing at all -- no errors as well.
Then I tried with custom code.
=code.sumlookup(LOOKUPSET(Field!COMP_ID.value,Field!COMP_ID.value,Field!ELEC_DATA.value,"DATASET2"))
The Result I am getting is "0".
The expected result would be the addition of ELEC_DATA like shown in the pic attached

Looks to me like you're using the LOOKUP function incorrectly. The LOOKUP function only requires 4 parameters to be used.
=LOOKUP([SourceValue], [DestinationValue], [LookedUpValue], "[SourceDataset]")
However, I'm not sure this is the best or even a viable solution to your issue. Honestly, this would be much easier if you were able to combine these two datasets into a single dataset query.
SELECT PAC2_ID, A.COMP_ID, DATE, ELEC_DATA
FROM TABLE1 A JOIN TABLE2 B ON B.COMP_ID = A.COMP_ID
From there, you can use a Grouping on the second Tablix based on PAC2_ID which removes the need for any expressions. It should sum the values automatically when you apply the grouping.

Alright Let's try something like this.
In your 2nd Tablix create one more Column let's call it "PAC2ID_Calculated".
Now for this Column we will use lookup Expression =Lookup(Field!COMP_ID.value,
Field!COMP_ID.value,
Field!PAC2_ID,
"FirstDataset")
Now what will this return in your new Column, It will return PAC2_ID for COMP_ID from first dataset and your 2nd Tablix will be something like below
Once you get this, Group it based on PAC2_ID, you will get expected Result.
You can Hide COMP_ID column.

Related

Trying to count records in SSRS from different data sets

I have an SSRS report that combines 5 reports into one. Each report is populated from a different stored procedure. The first page is a summary that is to provide a record count from each report. I've created fields in the stored procedure that provides the counts for each individual report: phycount and nonphyscount. I'm trying to create a table similar to this:
Active comes from one data set, Initial comes from another, Recert comes from another, etc.
I've been playing around with the Lookup and LookupSet but I'm just getting errors, plus I'm not sure if that's even the right direction.
Does anyone know how to do this?
Lookup and Lookupset are more for getting specific values out of a dataset. Very useful but not necessary for what you're trying to accomplish.
You can use aggregate functions SUM and COUNT to accomplish what you want to do. The cool thing about these functions is you can actually embed IIF statements inside of them.
I'm not sure exactly how your datasets look and are named but it would be something like this...
SUM(IIF(Fields!Type.Value = "PhyCount", 1, 0), "Active")
The sum function goes through every row of your dataset and sums the values you pass to it. The iif statement checks to see if the type field in the dataset is "PhyCount". If so, it returns 1, if not, 0. Since this will happen for every row, your SUM function will return a count of each row with status active.
edit: "Active" after the iif statement specifies the name of the dataset.
EDIT AGAIN: This solution apparently does not work in SSRS 2008.

SSRS: In a chart group by combining two datasets

I have a report that in the values I have 2 data sets, and then grouping by a location to display the data. If I use the one location within 1 dataset then sure one of the averages I am displaying is perfect but the other is incorrect showing the same result across the board.
No down I need to join these together to get an outcome.
here is what I have:
Values:
1. =Avg(Fields!Rating.Value)
2. =((sum(Fields!Low_rating.Value,"MIN_MAX_CCR") + sum(Fields!Max_rating.Value, "MIN_MAX_CCR")) / 2 ) / Count(Fields!Case_ID.Value, "MIN_MAX_CCR")
Category Grouping:
1.=lookup(Fields!CaseID.Value,Fields!Case_ID.Value, Fields!location.Value,"MIN_MAX_CCR")
So the first field is from the current dataset, the second is from the MIN_MAX_CCR dataset, the location is from the first data set, and then getting the data set for the case_ID.
Now when I run this I get this lovely error:
System.Web.Services.Protocols.SoapException: The Group expression for the grouping ‘Chart8_CategoryGroup’ refers to the field ‘location’. 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.
at
I just cant see a way around this - I cant combine the data in one query due to the nature of the query differences.
You are trying to return location from MIN_MAX_CCR, but it doesnt exist.
I would read the documentation or intellisense hints on the Lookup function to learn how to write it correctly.

How to sum calculated fields coming from nested list

In a report I have 2 nested list and the last one has a table inside.
I can easily sum values in the table and have them in the total field.
Inside the nested list I do special calculation with table total value.
I would like to be able to sum all these calculated values in the outer list.
What I need is a way for the nested list to expose its results to the outer list and a way to aggregate them. I don't want and probably cannot do the calculation again in the outer list, I want to sum the results coming from the inner list.
It seems a simple task but I spent the entire morning surfing for a solution !!
Sometimes instead of clicking here and there for a more formal way of adding a solution to thing I many a times find that it could be done in a simple fashion also..
what I mean by this that you can do like following
Right Click tablix row and insert new row below
Now at the cell where you want this aggregated sum total, you can simply use your existing expressions, that you are using in the previous cells, in this new cell where you want to display the results Something like this :
=Sum(Fields!Total1.Value, "DATASET1") + Sum(Fields!Total2.Value, "DATASET2")
See if it works for you, coz I always do like the same !

SSRS Report- Using two data sets

I want to do a calculation using two different datasets, but I cant seem to do it in the expression field. Any ideas on how I can add, multiply or divide using the two datasets? In the Fields, I added a new one and trying to set the expression only gives me DataSet1, but I want to add a DataSet2 field and a DataSet1 field.
Thanks guys
You can not directly use two data sets in there.
Imho you should move your data to db queries, then add a query that does your job, include this in your report then.
Alternative you can calculate some aggregat in a field, hide the field, do this with more/many as you want, then use your operatores on the result fields.

How to specify an order for the columns in a matrix?

I'm working on a SQL Reporting Services report (in VS.Net 2005) which displays a count of different data in a matrix. The columns have a count on the amount of customers in a certain set. So I have several columns like these: "1 employer", "2-9 employers", "10-19 employers" and so on.
The problem I have is that SQL Reporting Services sorts the columns in the matrix alphabetically. So I end up having the "10-19" column after the "1 employer" column but before the "2-9".
Is there any way to fix this?
Or maybe a trick to change the labels of the columns to that they sort right?
Thanks.
This can also be done by adding a new column to the query for the sort order. Then right click the column group from the matrix and select group properties. On the left hand side select sorting. From here you can specify another column to sort by instead of the column header. No custom formula needed.
We do a lot of SSRS Reports and this was always an issue with mdx. Here is one way we do it:
Set Sorting in the Grouping and Sorting Properties to sort by this expression:
=iif(Fields!DataSetField.Value = "ColumnName", "zzz", Fields!DataSetField.Value)
Where "zzz" could be a number or whatever you need it to be to help the sort and then select Direction as either Ascending or Descending base on this expression.
This may be a bit convoluted, but we had a similar problem and no means to change the SQL.
What we did was create a calculated field in the dataset that returns a number for each column and sorted the group on that number.
I had a similar problem but did not find a solution using a matrix in time - so I used a table - and put the needed logic of the matrix in my SQL-statements.
It's not the best thing to do but it works - it's fast enough and it don't takes that long to write.
I went into MATRIX --> PROPERTIES --> GROUPS.
Then, I "moved" the GROUP I wanted it to sort by UP in the list.
I went to PREVIEW, and it worked perfectly.
It even kept my column order the same.
Go to Edit Group - Sorting - Change the direction to descending for the expression.
For distinct numeric order of a Tablix use following line of code in expression.
=RunningValue(CountDistinct("YourTableName"),Count,"YourTableName")
Simply Go to tablix/Matrix Column Group and Right Click on the Group Properties then go Sorting and Delete the auto added record from Sorting.. Now your sorting will based on the Data you have added in Data set.