Sum Values based on Distinct Guids

混江龙づ霸主 提交于 2019-12-25 06:59:11

问题


I am having trouble getting the SUM of a column of values in SSRS.

My SQL query returns something like the following:

ID          Total
Guid1    4
Guid2    6
Guid3    1
Guid2    6
Guid4    6
Guid1    4

I have it grouped in my SSRS Report so it appears like this:

ID          Total
Guid1    4
Guid2    6
Guid3    1
Guid4    6

I need the sum of the Total column, but it wants to sum the ungrouped set of values instead of the grouped set. So I get

Sum(Total) = 27

But I WANT

Sum(DISTINCT? Guid Totals) = 17

I've tried the solutions that can be found on this page, with no luck: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/3c2626d8-e835-4bba-b946-7d6796e9c617/sum-distinct?forum=sqlreportingservices

I've also tried to add code behind the scenes that stores the distinct ids in a hashtable, and if it's not in the hashtable, add it to a global total; which I call from each row of the table, and then display the global total at the bottom, but that's not working either.

Any ideas?


回答1:


pretty sure you can Sum the grouped field in ssrs.

=SUM(MAX(Fields!value.value,"GuidGroupName"))


来源:https://stackoverflow.com/questions/31840290/sum-values-based-on-distinct-guids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!