【问题标题】:Showing Percentage in SSRS Tablix在 SSRS Tablix 中显示百分比
【发布时间】:2016-12-20 19:31:54
【问题描述】:

我正在使用 Visual Studio 2012 和 SQL Server 2012。我的问题是关于如何根据我目前拥有的字段在我的 SSRS Tablix 中显示百分比。

我有一个 WithinRequirements 字段,我使用 case 语句告诉我特定的 Business_ID 是否符合要求。在这种情况下,如果名称为 HeadquartersBusiness_ID 在 10 天内完成,则它会收到 1,如果没有则收到 0。

CASE WHEN AgeBusiness >= 0 AND AgeBusiness <10 AND [Name] like '%Headquarters%' THEN 1
ELSE 0
End AS WithinRequirements

由此,应用我的过滤器和其余查询,我得到大约 601 条 Business_ID 记录,结果要么是 0,要么是 1。

现在我正在尝试在我的 tablix 中创建一个列来显示 WithinRequirements 的百分比。

基本上,我试图在SSRS 中为以下列获取一个表达式:

(Count of Business_ID where WithinRequirements = 
                1/Total Number of Business_ID where WithinRequirements = 1 or 0) * 100)

我不知道如何表达。有人可以帮我解决这个问题吗?我试过了:

= Count(Fields!WithinRequirements.Value)/Sum(Fields!WithinRequirements.Value)* 100

作为我的表达,但这不起作用。

任何帮助将不胜感激,并在此先感谢您。

【问题讨论】:

    标签: reporting-services sql-server-2012 expression ssrs-2012 percentage


    【解决方案1】:

    试试这个

    Sum(Fields!WithinRequirements.Value)/Count(Fields!WithinRequirements.Value) * 100

    【讨论】:

    • 我明白了,你必须正确对待WithinRequirements,我猜你缺少它的数据。所以它会在sumcount 失败,在得到最终比率之前检查你的最终结果中是否有 null 或为空
    • 怎么不工作了?此外,虽然@LONG 提供的答案将返回一个百分比值,但它不会在报告中显示为百分比。为此,请不要使用乘数以返回十进制值,然后将文本框/占位符格式化为百分比
    • @LONG - 所以目前在WithinRequirements中,我拉入的所有数字都有0或1,所以没有NULL或空值。
    • @Paul - 目前它不断返回 0% 或 NaN。我已经将文本框格式化为百分比。
    • Nan (Not a Number) 表示你发生了 0/0。您在报告中有哪些分组?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多