SQL SSRS根据行总数计算列的百分比

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22205659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:15:14  来源:igfitidea点击:

SSRS calculate percentage of column based on row total

sqlreporting-servicesexpression

提问by grahamie

I have a data set which looks like this

我有一个看起来像这样的数据集

+------------+-----------------------------+
| user_name  |             role            |
+------------+-----------------------------+
| User A     |  Admin, System              |
| User B     |  Editor, Power User, System |
+------------+-----------------------------+

I would like to calculate the total of each column (A,B) as a percentage of the Row total to look like

我想计算每列(A,B)的总数作为行总数的百分比,看起来像

+-------+-----+-----+-------+
| Month |  A  |  B  | TOTAL |
+-------+-----+-----+-------+
| Jan   | 90% | 10% | 100%  |
| Feb   | 90% | 10% | 100%  |
| Mar   | 75% | 25% | 100%  |
+-------+-----+-----+-------+

I have tried a Table and Matrix cant seem to get either to work:

我试过一个表和矩阵似乎无法正常工作:

enter image description here

在此处输入图片说明

回答by Ian Preston

Your % value expression should be something like:

你的 % value 表达式应该是这样的:

=Sum(Fields!Income.Value) / Sum(Fields!Income.Value, "RowGroupName")

Where RowGroupNameis the name of your defined Monthrow group, as you may notice with the example given.

RowGroupName您定义的Month行组的名称在哪里,正如您在给出的示例中可能注意到的那样。

This applies the total Incomefor a particular Fee_To/ Monthgroup to all Fee_Tototal Incomevalues in that Monthgroup.

这将Income特定Fee_To/Month组的总计应用于该组中的所有Fee_To总计IncomeMonth