SSRS groupings and sub totals - reporting-services

Working with SSRS and need to be able to accomplish subtotalling in the following manner:
I have a table, grouped on 'claim'; each claim has multiple lineitems.
I need to have each claim and the sub totals as claim1 amt, claim1 amt, subtotal for claim1.
Then Claim2 amt, claim2 amt, subtotal for Claim2
So the output would look like:
CLAIM Amt
400-1 150.00
400-2 100.00
Subtotal for Claim 400 250.00
500-1 75.00
500-2 100.00
Subtotal for Claim 500 175.00
and so forth.
It's the 'Subtotal" row in between i can't figure out. I can't get it to show after the individual grouping in the table. I need it to show after, and the end of the grouping, as it is now i insert the row with the summary of amt, and it sums correctly, but it shows up in between each row, as opposed to at the end of the grouping, then the next claim, etc.
How can I do this?

You can create a 'subtotal' group (parent to your claim group). Then you would add a group expression for said group to something like:
=LEFT(Fields!Claim.Value,3)
Or if it's not always three digits, then perhaps this will work:
=LEFT(Fields!Claim.Value, InStr(Fields!Claim.Value,"-"))

If you create a tablix and grouping as below, you should achieve the result you desire:

Related

Add sum of columns to chart SSRS

I have searched all over and cannot seem to find a definitive answer for this issue! I have a simple chat here grouped on the 5 categories below detailing the Sums of their SqFt.
I want to add a Total Column to the graph ~(Total = 11M sqft). Can this only be done in SQL? It is a bit puzzling for me to do this because the query already sums the sqft for each row (as a nested query). I would need to Sum(sum(sqft)) in order to produce what I want, however, I dont believe this will work on the group level.
Sample Data set:
ID| Type| Sqft|
12| OF| 500
14| IN| 1294
99| OF| 12042
24| ME| 92043
15| IN| 13945
16| OW| 2650
Can this be done in the report builder?
Thanks!
You can add a Total row in your query by using GROUPING SETS operator. Once the total is in the dataset it is trivial to show the column in the chart.
Based on the data sample you posted you can use a similar query to the below:
SELECT
CASE
WHEN GROUPING_ID(Type) = 1 THEN 'TOTAL'
ELSE Type
END [Type],
SUM(Sqft) Sqft,
GROUPING_ID(Type) [Grouping]
FROM your_table
GROUP BY GROUPING SETS ((Type), ())
Check this Live Demo
If you are confused by the above query you can simply use the union operator to add a row to the end of your current dataset.
SELECT
ID,
[Type],
Sqft
FROM your_table
UNION ALL
SELECT
NULL,
'Total',
SUM(Sqft)
FROM your_table
Now just create your chart using the produced dataset.
Let me know if this helps.

Reporting Services How to get the Count() value from IIF

I have this table with a column named Open_Time which contain a datetime value. I would like to have another column named Total Ticket In June with the total count of ticket in June, so I've inserted the expression like below:
=Count((IIF(DatePart("m",Fields!Open_Time.Value,0,0) = "6",1,0)))
but there seems to be an error. To make myself clear, the table should look like this:
Assigned Name Ticket ID Open_Time Total Ticket in June
Ivan 001 3/28/2014 2
002 6/24/2014
003 6/11/2014
I would like to get value "2", which is the total number of ticket in June. Any idea? :)
You need to switch to a Sum aggregate instead of Count (based on your IIF, Count will count every row instead of giving you a total number of occurences):
=Sum(IIF(DatePart("m",Fields!Open_Time.Value,0,0) = 6, 1, 0))
From your table it's hard to tell your row groupings, but keep in mind that you'll only get the sum you expect if that expression is on a totals row (i.e. if you use that expression on the detail row it will simply list 1 or 0 for each date).
Try this:
=Count((IIF(DatePart(dateinterval.Month,Fields!Open_Time.Value,0,0) = 6,1,0)))

How do I write report from 2 different dataset linked by ID?

I am building a report in report builder. I have 2 dataset, they can't be merged because of their complexity. What I would like to do is make a report where it use the ID from the first dataset to look up data in the 2nd dataset. Is this possible? The following are example, not exact code, but what I need:
First Dataset:
select itemID from Items
Second Dataset:
select itemID, saleAmount, salePrice from Sales
I would like to setup my report like this:
ItemID | Sale Count | Sale Price
--------------+-------------------------------------------------------------+------------
Items.itemID | sum(Sales.saleAmount) where items.itemID = Sales.itemID | sum(Sales.salePrice ) where items.itemID = Sales.itemID
So the end result will be like this:
ItemID | Sale Count | Sale Price
--------------+-------------------------------------------------------------+------------
1 | 11223 | $123123
2 | 4537 | $8375
Is this possible? Maybe with Conditional Lookup?
It's a shame you can't join the data when creating the datasets.
Failing that, I can think of a couple of other options:
Use LookupSet and custom code
This excellent answer How to combine aggregates within a group with aggregates across groups within SSRS has a perfect example of how you might do this.
Basically, you add custom code in a function (e.g. SumLookup) that accepts the results of a LookupSet call and returns the aggregated value. You'd have expressions like the following in your report:
=Code.SumLookup(
LookupSet(Fields!itemID.Value, Fields!itemID.Value, Fields!saleAmount.Value, "Sales")
)
I created a quick test and it works perfectly.
Use subreports
To do this you'd create table based on the Items dataset, then in the detail row you'd embed a subreport to display the Sales information.
The subreport would need an itemID parameter to filter the Sales appropriately, you would set the parent table to pass =Fields!itemID.Value to the subreport - this would then repeat for each itemID row and display the relevant Sales data.
For what it's worth, I'd look at the first option - there is some custom code, but it's straightforward, and that way you wouldn't need to deploy multiple reports. Just seems cleaner to me.

Sum of distinct in SSRS

I have to get distinct rows sum in SSRS expression.
**StudentId TestScoreMath CurriculumEnrolled EnrollStatus**
100 200 Nursing Enrolled
100 200 Physical Enrolled
200 100 Tech Enrolled
Total Student TestScoreMath should be 300 not 400. I tried using the expression
=Sum(Fields!TestScoreMath .Value, "table1_Group3")
How can I SUM the value of TestScore of distinct students? I need this only in SSRS.
In SSRS 2005, this is not too easy. I would add embedded code to keep a running total. You can have the custom code to check to see if the current student ID matches the last. If so, then don't add another test score to the total. Or you could group by Student ID and call your custom code only in the header or footer of that group.
This sample shows totaling all rows: you'll need to add to this to track the studentID.

How to do SUM(VacancyID) without Duplicates while also showing Count(VacancyStartID) in the same Group?

In SSRS 2005 I am reporting on all available posts by regional office, listed by region,office,vacancyID.
I then display a total per office on how many people started in a particular vacancyID by doing a Count(VacancyStartID).
In the same group row with the Count(VacancyStartID) I need to display SUM(VacancyID).
However at present this does not give the correct SUM, because some vacancies have multiple VacancyStartID's and hence the vacancyID is listed few times, like so:
office vacancyID Number_of_vacancies VacancyStartID (person who started a job)
1 1 2 4567
1 1 2 5678
Totals: 4 (needs to be 2) 2
P.S. Note:These questions are not applicable in this instance:
How can I remove duplicate rows?
How do I remove "duplicate" rows from a view?
Using multiple COUNTs and SUMs in a single SQL statement
If it's in the Underlying SQL Server call...
You can do ...SUM(DISTINCT VacancyID)... like you can COUNT (DISTINCT ..)
Edit:
SELECT
col1, col2, SUM(DISTINCT Number_of_vacancies) as foo, COUNT (VacancyStartID) as bar
FROM
MyView
...
If it's in the table or for a cell in the report, then there is no equivalent in the SSRS SUM function.
Do some grouping already in your query and then make a group with a simple Count in SSRS.