如何在SSRS报表中添加动态数据透视表结果?

5

我是一名新手,需要使用Pivot和SSRS创建报告,这个报告与透视表类似。

报告布局如下:

           Area_1  Area_2  Area_3  Area_4  ...  Area_N
A_Percent
B_Percent
C_Percent
D_Percent

由于“Area_N”是动态的,因此我的表格布局如下:

Area   A_Percent   B_Percent   C_Percent   D_Percent
----   ---------   ---------   ---------   ---------
Area_1    45           55         66           77
Area_2    22           33         11           55 
Area_3    12           45         88           36
Area_4    67           23         37           28
...
Area_N    76           67         35           28

我的问题是:

  1. 如何基于上述结构创建数据透视表?
  2. 我的SSRS报告可以从数据透视表中读取数据吗?

欢迎所有专家的评论。

非常感谢!

1个回答

17

首先,你可以在SSRS 2005中使用矩阵(或在后续版本中使用Tablix)来实现你想要的效果。但是,你所面临的问题是,矩阵更适用于垂直格式的内容。因此,在你的情况下,需要这样查询:

SELECT Area, 'A_Percent' as Type, A_Percent as Val FROM YourTable
UNION ALL
SELECT Area, 'B_Percent' as Type, B_Percent as Val FROM YourTable
UNION ALL
SELECT Area, 'C_Percent' as Type, C_Percent as Val FROM YourTable
UNION ALL
SELECT Area, 'D_Percent' as Type, D_Percent as Val FROM YourTable

那么你应该有一个结果集,看起来更像这样:

Area    Type       Value
Area_1    A_Percent  50
Area_2    A_Percent  42
Area_3    A_Percent  20
Area_1    B_Percent  12
Area_2    B_Percent  28
Area_3    B_Percent  16
现在您可以在矩阵控件中使用此内容。将区域字段拖放到“列”组中。将类型字段拖放到“行”组中,并将值拖放到中间(它将变成SUM()表达式)。 Designer Example... 全部完成 :)

谢谢Charleh!它完美地运行了!现在我想稍微更新一下,将参数添加到查询中。 - marcus.the.programmer
您的详细回答将不胜感激。立即生效。 - blind Skwirl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接