100%条形图SQL - 是/否答案

时间:2017-08-09 10:29:45

标签: reporting-services bar-chart

Sql Server 2016 /报表设计器:

不确定这是否是提出此问题的正确标题所以如果我错了请纠正我。

我有以下内容:

 SELECT [aField6] AS [CleanAndTidy],
        [aField10] AS [HandWash],
        [aField8] AS [PPEStorage],
        [aField14] AS [PipesAndFittings],
        [aField12] AS [COSHH]
 FROM vAdvF_265
 GROUP BY [aField6], [aField10], [aField8], [aField14], [aField12]

答案如下:

CleanAndTidy    HandWash    PPEStorage  PipesAndFittings    COSHH
No                 No            No           No            No
No                 Yes           Yes          Yes           Yes
Yes                No            No           Yes           Yes
Yes                No            Yes          Yes           Yes
Yes                Yes           No           No            Yes
Yes                Yes           No           Yes           No
Yes                Yes           Yes          No            No
Yes                Yes           Yes          Yes           No
Yes                Yes           Yes          Yes           Yes

我希望每列的100%堆积条形图(是/否为50/50),但在SSRS中使用时,我似乎无法找到提供数据的正确方法到图表。

我也尝试过:

    SELECT [Type1], [Count] -- YES Count
 FROM (
 SELECT 
     SUM(CASE WHEN [aField6]='yes' THEN 1 ELSE 0 END) AS [CleanAndTidyYes],
     SUM(CASE WHEN [aField10]='yes' THEN 1 ELSE 0 END) AS [HandWashYes],
     SUM(CASE WHEN [aField8]='yes' THEN 1 ELSE 0 END) AS [PPEStorageYes],
     SUM(CASE WHEN [aField14]='yes' THEN 1 ELSE 0 END) AS [PipesAndFittingsYes],
     SUM(CASE WHEN [aField12]='yes' THEN 1 ELSE 0 END) AS [COSHHYes]
     FROM vAdvF_265
 ) sums
 UNPIVOT
 ([Count] FOR [Type1] IN
     ([CleanAndTidyYes], [HandWashYes], [PPEStorageYes], [PipesAndFittingsYes], [COSHHYes])
 ) AS unpivoted1

 UNION

 SELECT [Type], [Count] --NO Count
 FROM (
 SELECT 
     SUM(CASE WHEN [aField6]='no' THEN 1 ELSE 0 END) AS [CleanAndTidyNo],
     SUM(CASE WHEN [aField10]='no' THEN 1 ELSE 0 END) AS [HandWashNo],
     SUM(CASE WHEN [aField8]='no' THEN 1 ELSE 0 END) AS [PPEStorageNo],
     SUM(CASE WHEN [aField14]='no' THEN 1 ELSE 0 END) AS [PipesAndFittingsNo],
     SUM(CASE WHEN [aField12]='no' THEN 1 ELSE 0 END) AS [COSHHNo]
     FROM vAdvF_265
 ) sums
 UNPIVOT
 ([Count] FOR [Type] IN
     ([CleanAndTidyNo], [HandWashNo], [PPEStorageNo], [PipesAndFittingsNo], [COSHHNo])
 ) AS unpivoted1;

这给了我:

Type1                                                                                                                            Count
-------------------------------------------------------------------------------------------------------------------------------- -----------
CleanAndTidyNo                                                                                                                   2
CleanAndTidyYes                                                                                                                  18
COSHHNo                                                                                                                          3
COSHHYes                                                                                                                         17
HandWashNo                                                                                                                       7
HandWashYes                                                                                                                      13
PipesAndFittingsNo                                                                                                               2
PipesAndFittingsYes                                                                                                              18
PPEStorageNo                                                                                                                     4
PPEStorageYes                                                                                                                    16

虽然第二个给了我我追求的数量,但我仍然在努力将其变成100%的图表而不是每列的是/否答案。

有人可以帮助我指出正确的方向/提供任何建议或其他方法吗?

1 个答案:

答案 0 :(得分:0)

为条形图值添加表达式。在表达式中添加如下代码:

=SUM(IIF(Fields!CleanAndTidy.Value = "Yes", 1, 0))

sum函数将为数据集中的每一行添加总值。然后,您可以在里面添加IIF表达式来评估每个列,并根据表达式返回一个值。在上面的示例中,如果CleanAndTidy是"是",则返回1。如果不是,则返回0。最终结果将是"是"答案。

然后您可以冲洗并重复手洗等。冲洗并重复?得到它?