SSRS 2008 中的表达式总计未显示正确的数据
一个长期的读者。该网站上有大量信息。
希望这不是一个愚蠢的问题,但我一直在努力研究如何在报告中获得正确的总数。
我对简单总计有疑问。我有一份报告,它取两个数字的差并显示结果,结果有负数和正数。在报告的底部我想要差异的总和。由于某种原因,总数甚至相差甚远。
这是我的数据:
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"**
如您所见,数据显示的总差异为 71,118.44 美元,而实际差异应该是 (90,581.56 美元)。
这是获取差异结果的表达式:
=Sum(Fields!TotalSales.Value)-Fields!Budget.Value
我右键单击文本框并选择“添加总计”以获取差异字段的总计。我也尝试过这个建议:
=Sum(Fields!TotalSales.Value)-Sum(Fields!Budget.Value)
还有这个:
=ReportItems!textbox14.Value - ReportItems!textbox15.Value
另一件事要提到的是专家上有分组。总销售额字段是该特定月份销售额的集团总计。预算字段是组外的单个字段。
这似乎是理所当然的,它应该有效。也许有人可以给我一些指导。
提前致谢。
编辑:
感谢您的帮助,但不幸的是问题比这更复杂:)我应该对此更加清楚。我从 3-4 个数据库中提取数据,但它们没有可链接的公共字段。我使用行号来减少重复的小计并将其设置为 0。我在预算编号上使用行号,但我得到的数据是假的。这是我拥有的数据:
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
这是我想要的数据:
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
如果预算数字重复多次,我希望它为 0。我认为这就是我的总计在 SSRS 中无法正确显示的原因。我通过获取销售员小计的 GrandTotal 并从放入组页脚的预算字段中减去它们来计算差异字段(因为我是新人,所以我无法发布图像,抱歉。这是超链接)
http://i55.tinypic.com/124jw2u.png
这也是我的 SQL 语句:
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
这有一点帮助吗?我试图避免执行存储过程,因为我对 SSRS 和 SQL Server 还很陌生。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种选择是计算 SSRS 数据集中使用的 SQL Server 查询中的总销售额。以下示例显示了一个示例。该示例是根据我对表格的设想的假设创建的。该报告是在 SSRS 2008 R2 中创建的,使用的数据库是 SQL Server 2008 R2。
假设源表如屏幕截图#1所示。该表未标准化,但此处仅作为示例显示。
报表数据库的查询如屏幕截图#2所示。该查询也在SSRS 数据集查询部分下给出。
报告的设计如屏幕截图 #3 所示。 a 部分中的表达式为
=Fields!TotalSales.Value - Fields!Budget.Value
,b 部分中的表达式为=Sum(Fields!TotalSales.Value, "SalesData") - Sum( Fields!Budget.Value, "SalesData")
。屏幕截图#4 显示报告执行。
希望有帮助。
SSRS 数据集查询:
屏幕截图 #1:
屏幕截图 #2:
屏幕截图 #3:
屏幕截图 #4:
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 wasSQL 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:
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!