Expression total not displaying correct data in SSRS 2008 - reporting-services

A long time reader. A great wealth of info on this site.
Hopefully this isn't a dumb question, but I've been struggling on how to get the correct totals in my report.
I'm having issues with simple totals. I have a report that takes the difference of two numbers and shows the result, with the results being both negative and positive. At the bottom of the report I want a total sum of the difference. The totals are not even close for some reason.
Here's my data:
Correct Data
Specialist Total Sales Budget Difference
DICK "$35,174.00" "$63,530.00" "($28,356.00)"
NATHAN "$16,193.00" "$40,000.00" "($23,807.00)"
PAUL "$52,096.00" "$55,000.00" "($2,904.00)"
STEVE "$31,185.44" "$66,700.00" "($35,514.56)"
**Totals: "$134,648.44" "$225,230.00" "($90,581.56)"**
Incorrect Data that is in my report
Specialist Total Sales Budget Difference
DICK "$35,174.00" "$63,530.00" "($28,356.00)"
NATHAN "$16,193.00" "$40,000.00" "($23,807.00)"
PAUL "$52,096.00" "$55,000.00" "($2,904.00)"
STEVE "$31,185.44" "$66,700.00" "($35,514.56)"
**TOTALS: "$134,648.44" "$225,230.00" "$71,118.44"**
As you can see, the data shows the total differece as $71,118.44 when it should be ($90,581.56).
Here is my expression to get the result of the Difference:
=Sum(Fields!TotalSales.Value)-Fields!Budget.Value
I right clicked on the text box and selected "Add Total" to get a Grand Total for the Difference field. I also tried this suggestion:
=Sum(Fields!TotalSales.Value)-Sum(Fields!Budget.Value)
And this:
=ReportItems!textbox14.Value - ReportItems!textbox15.Value
Another thing to mention is there is grouping on Specialist. The Total Sales field is a Group total for their sales for that particular month. The Budget field is a single field outside of the group.
This seems like a no brainer that it should work. Maybe someone can give me some guidance on this.
Thanks in advance.
EDIT:
Thanks for the help, but unfortunately the issue is more complicated than that :) I should have been more clear on that. I'm pulling data from 3-4 databases and they don't have a common field to link on. What I'm using a Row number to reduce duplicate subtotals and set them to 0. I using a rownumber on the Budget number, but the data I was getting back was bogus. Here's the data I have:
Name Team SubTotal Budget
SCOTT Vikings 202 25000.00
SCOTT Vikings 1890 25000.00
SCOTT Vikings 5167 25000.00
SCOTT Vikings 20256 25000.00
SCOTT Vikings 0 25000.00
SCOTT Vikings 0 25000.00
And here's the data I want to have:
Name Team SubTotal Budget
SCOTT Vikings 202 25000.00
SCOTT Vikings 1890 0.00
SCOTT Vikings 5167 0.00
SCOTT Vikings 20256 0.00
SCOTT Vikings 0 0.00
SCOTT Vikings 0 0.00
If the budget number repeats more than once, I want it to be 0. I think this is the reason my totals aren't showing correctly in SSRS. I'm calculating the Difference field by taking the GrandTotal of the Salesman's subtotals and subtracting them from the Budget Field that was put into the group footer (since I'm new I can't post images, sorry. Here's the hyperlink)
http://i55.tinypic.com/124jw2u.png
Here's my SQL Statement also:
WITH InvoicedAndPaid
AS
(
SELECT KEY1
,ltrim(rtrim(CustomText01)) as CustomText01
,ROW_NUMBER() OVER(PARTITION BY DocNo ORDER BY DocNo) AS RowNumber
,SubTotal
,OrderDate
,INVOICEDATE
FROM DocumentHeadersItems AS AA
JOIN SorArCombined AS BB
ON AA.DocNo = ('AA' + BB.CustomerPoNumber)
JOIN CONTACT1 AS CC
ON AA.SoldToCMAccountNo = CC.ACCOUNTNO
WHERE CreatedBy != 'NOAHDM'
AND KEY1 IN (#org)
AND SubTotal != 0
AND LEN(INVOICE) > 0
AND
(
(
CUSTOMER = 'QAA'
AND (INVOICEDATE IS NOT NULL)
AND (DATEPART(MM,INVOICEDATE) = DATEPART(MM,#start))
AND (DATEPART(YYYY,INVOICEDATE) = DATEPART(YYYY,#end))
)
OR
(
CUSTOMER != 'QAA'
AND (YearInvBalZero > 0)
AND (YearInvBalZero = DATEPART(YYYY,#start))
AND (MonthInvBalZero = DATEPART(MM,#start))
AND (YearInvBalZero = DATEPART(YYYY,#end))
AND (MonthInvBalZero = DATEPART(MM,#end))
)
)
)
SELECT bb.team_id
,bb.specialist_id
,dd.Budget
,cc.team_name
,KEY1
,CustomText01
,CASE WHEN RowNumber = 1 THEN SubTotal ELSE 0 END as SubTotal
FROM InvoicedAndPaid as aa
join SalesReporting.dbo.team_members as bb
on rtrim(aa.CustomText01) = rtrim(bb.specialist_name)
join SalesReporting.dbo.team_master as cc
on bb.team_id = cc.team_id
join SalesReporting.dbo.sales_goals as dd
on bb.specialist_id = dd.specialist_id
WHERE dd.time_span LIKE 'M%'
AND dd.month = DATENAME(MONTH,#end)
AND dd.Org = aa.KEY1
AND cc.team_name in (#team)
AND dd.period_no = DATEPART(MM,#end)
ORDER BY team_name, CustomText01
Does this help out a little? I'm trying to avoid doing a Stored Procedure because I'm fairly new at SSRS and SQL Server.

One option would be to calculate the total sales in the SQL Server query that is used in SSRS dataset. Following example shows a sample. The sample was created based on an assumption of how I envisioned the table might be. The report was created in SSRS 2008 R2 and database used was SQL Server 2008 R2.
Assuming that the source table is as shown in screenshot #1. The table is not normalized but it is shown here just for an example.
The query for the report database would be as shown in screenshot #2. The query is also given under SSRS Dataset Query section.
Report would be designed as shown in screenshot #3. Expression in section a would =Fields!TotalSales.Value - Fields!Budget.Value and Expression in section b would be =Sum(Fields!TotalSales.Value, "SalesData") - Sum(Fields!Budget.Value, "SalesData").
Screenshot #4 shows report execution.
Hope that helps.
SSRS DataSet Query:
SELECT Specialist
, SUM(Sales) AS TotalSales
, SUM(DISTINCT(Budget)) AS Budget
FROM dbo.SalesData
GROUP BY Specialist
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:

In this rare case, I had to put in a footer and reference the sum formulas to the actual text boxes. Very weird that this worked but the regular expressions did not.
I appreciate your help on this!

Related

SQL Dsum based on criteria

I'm trying to sum all amounts where column 'weight'=2 and do so according to months and format it in dollar currency. Here is what I have so far:
SELECT
Format([Final Action Date],"yyyy-mm") AS [Month],
DSum("[Amount]","C02: Underwriting Audit Case Detail Report Record Selection"," [Weight] = '2'") AS FA_Critical,
Sum(IIf([Weight]="2",1,0)) AS Critical_Count
FROM [C02: Underwriting Audit Case Detail Report Record Selection]
WHERE ((([C02: Underwriting Audit Case Detail Report Record Selection].[Case Type]) Not In ("**Target IUP")))
GROUP BY Format([Final Action Date],"yyyy-mm");
Here is the result that I have so far:
Month FA_Critical Critical_Count
2015-01 2035480 2
2015-02 2035480 2
2015-03 2035480 0
2015-04 2035480 1
Here is what I want:
Month FA_Critical Critical_Count
2015-01 $1,350,000 2
2015-02 $510,480 2
2015-03 $0 0
2015-04 $175,000 1
Please help.
Thanks.
Your problem is in the criteria for your DSum, it's looking at [Weight]='2' across the whole recordset, which is why you are getting the same value for all 4 records. The DSUM is not partitioned by the GROUP BY the same way that the SUM is.
Use a SUM instead of the DSUM, and instead of using 1,0 for true and false, use the value of your amount column:
Sum(IIf([Weight]="2",[Amount],0)) AS FA_Critical

Merging multiple Rows in ssrs report to a single one

I need help regarding SSRS Reporting my data is Coming from a Query and I also have added the Column Group Named as Subject Name Showing on the top of the Table() Also Added ApplicantID as Row Group and FName as a Row Group in the Report to fulfill my requirement that was just to show
Since I am not Sure how many subjects a user can select its all decide on the run time so i did added the Subject name as a column group
All the Subject records in a single row for a specific ApplicantId Instead of showing below my Requirement is
It Should looks like as a table
Anatomy Surgery Zoology
Part ISt
14 Hanan Qureshi Iqbal Qureshi 15.00 20.00 10.00
15 Tasneem Alam Imtiaz Alam 30.00 10.00 20.00
etc instead of Showing in a seperate row it should show in a single row
Details group is your problem as #hemanth said you need to remove this and add in an aggregate function (max, min, sum, average) any will work since there is only one value for each SubjectName, Obtained Mark Combo. this will give you all the marks on one line for each applicant.

Group in SSRS Report

I have some issue in my sales report . I want to make a report like this, in which two columns are there..
Team TotalSales
Team A 1000
a1 500
a2 500
Team B 400
Team C 800
Total 2200
here a1 and a2 are sub part of Team A.1000 is sum of a1 and a2 ToltSales.
Please help..
Start with the Table Wizard - set your team name to the grouping field, and your values in the details field. Enable totals lines and the layout you'd prefer. The resulting table will be pretty close to what you need logic-wise, you'll just need to format it how you'd like.
I'd advise taking some time to look at how the wizard sets up grouping properties, as the wizard won't be useful at all when you need to get into very complicated tables with multiple levels of grouping.

Populating with '0' when Data in SSRS Does not exist

I'm trying to create a report in SSRS where I have a matrix, which has gender as the column headings and specifically defined agegroups as the rows. The report is sorted by date (ie, the records being displayed are filtered by the modifedAt value). My problem is that i wish for all of the age group categories to be displayed, even if the dataset does not return any data for that row.
So, for example, if i set the date to be a date where there are no db rows where there are Age5-16 children in - I still want to display the category name, but just have the cells related to that row to display '0'. Instead, the report just drops the whole row because, obviously the query returns no data.
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together? I'm stuck here so any help is appreciated!
I can think of a few ways to do this:
DataSet level
Instead of just returning the relevant data in the underlying data in the DataSet, include all the categories you want to display in all cases.
e.g. For a database query it might be the difference between an inner and left join, i.e. going from something like:
select *
from AgeGroup
inner join MyData on ...
to:
select *
from AgeGroup
left join MyData on ...
So the report always has all the age groups to display. Where there are NULL values, just display 0.
I think this is the best option if you have control over the DataSet - you won't have to update your report at all, with luck the actual DataSet changes should be minimal, there is still only one DataSet call, and it's by far the simplest to maintain.
Hard code groups into the report
Here you include a table header row for each group you want to display, so these are always displayed in all cases.
Here you have some sort of conditional expression to display the values, e.g. For each group row it will be tailored to that group:
=Sum(IIf(Fields!AgeGroup.Value = "5-16", Fields!Amount.Value, Nothing)
This is not too flexible and will need updates as you change groups, and doesn't have as many options for layout. There is still only one DataSet call, so that is a plus.
Subreports
You can have a parent DataSet that displays one row for each age group, then embed a subreport in each row that displays the data you want for that row.
This allows you flexibility in layout but it will add complexity to the report(s) and will mean that you make a lot of DataSet calls that could be avoided with other options.
I know this is old, but I wanted to elaborate on Ian's section 1 above using joins at the dataset level. (His answer was super helpful to me for a report I'm working on.)
per op:
Is the solution to have a separate dataset that brings back the entire list of categories and then somehow fit them together?
That is how I've handled it successfully, but you can do so without actually creating a separate dataset by using common table expressions (or temp tables, of course).
For these example tables:
AGE_Table
ID Group Group_Desc Toys
1 A 00-10 Teddy Bear
2 B 11-20 Video Game
3 C 21-30 Sports Car
4 D 31-40 Mansion
5 E 41-50 Jewelry
People_Table (filtered for whatever date)
ID Name Age Gender Age_Group
1 Ariel 07 F A
2 Brandon 23 M C
3 Chelsea 27 F C
4 Derek 06 M A
You want to see 2 results for the 00-10 row, 2 for the 21-30 row, and then still see rows for the other age groups even if there aren't any results.
We want to create a dataset with all the different age groupings and then join on it. Behold a solution using common table expressions:
with CTE_Age AS
(SELECT Distinct Age_Group from AGE_Table)
SELECT ID, Name, Age, Gender, CTE_Age.Age_Group FROM People_Table
RIGHT JOIN CTE_Age ON
People_Table.Age_Group = CTE_Age.Age_Group
This will return:
ID Name Age Gender Age_Group
1 Ariel 7 F A
4 Derek 6 M A
NULL NULL NULL NULL B
2 Brandon 23 M C
3 Chelsea 27 F C
NULL NULL NULL NULL D
NULL NULL NULL NULL E
Once you have that in your dataset, you can change NULL values to 0 on the report builder side -- I think in 2008R2 the default is just blank.

Reporting services put data from two DataSet rows in one tablix cell

I need to create report with table which looks like this
Country 1 Country 2 Country 3 Total
Category 1 1(2) 2(1) 5(6) 8(9)
Category 2 2(3) 2(1) 4(0) 8(4)
Category 3 3(2) 2(1) 3(1) 8(4)
Total 6(7) 6(3) 12(7) 24(17)
Report contains data about TFS WI's and has information about current week's WI count and last weeks WI count (in brackets)
Data set on which this report is based on MDX query against TFS warehousw cube and has such structure:
Category Country Week Count
1 1 this 1
1 2 this 2
1 3 this 5
1 1 last 2
1 2 last 1
1 3 last 6
Trouble is, I cann't find a way how to concatenate data about current and last weeks incident count in one cell. I have toyed around with idea to do it in MDX, but with my limited MDX skills I can't see how it could be done.
Rowgroup on Category.
Columngroup on Country.
Inside the cell you should be able to have 2 placeholders with the second one in brackets. The first expression should be:
=Sum(iif(Fields!Week.Value = "this", Fields!Count.Value, 0))
The second one should be:
=Sum(iif(Fields!Week.Value = "last", Fields!Count.Value, 0))
In MDX you could create two calcs - this and last week (of course you'll need to change this to work with your cube):
WITH
MEMBER [Measures].[thisWeekCount] AS
([Date].[Week].[this], [Measures].[Count])
MEMBER [Measures].[lastWeekCount] AS
([Date].[Week].[last], [Measures].[Count])
SELECT
{
[Measures].[thisWeekCount],
[Measures].[lastWeekCount]
} ON 0,
{
...
} ON 1
FROM [Your Cube]
Then, you can use them within placeholders as jimconstable explained, but without the iif functions.
Thank you all for your answers!
I found out that main problem (reporting services allows only one measure on columns) can be solved by using Analysis server OLE DB provider. There are some drawbacks, like that parameters are not supported, but I can live with this.