War*_*ren 5 sql reporting-services reportbuilder3.0
请原谅这个问题的模糊标题.也许下面会更好地提出我的问题.
请考虑以下聚合表:
Fruit Units FruitSales%
----- ----- -----------
Apples 10 ?
Oranges 20 ?
Bananas 10 ?
NonFruit 10 ?
TOTAL 50 ?
Run Code Online (Sandbox Code Playgroud)
我需要FruitSales%列:Fruit / (Total - NonFruit)
如果NonFruit是其自己的产品名称,如何在Tablix中将其值用于其他计算?
我想我的FruitSales%的公式是这样的:
Sum(Fields!Units.Value) / (ReportItems!txtTotalUnits.Value - SumIf(Fields!Fruit = "NonFruit", Fields!Units.Value)
Run Code Online (Sandbox Code Playgroud)
但是,SumIf不存在,即使它确实存在,它也将特定于当前行.
虽然我在这里,ReportItems!txtTotalUnits.Value但我明显地命名了那个文本框,但有没有更清晰的方式来引用它?
假设底层 DataSet (我称之为FruitDataSet)如下所示:

我根据这些数据创建了一个简单的报告:

水果销售百分比表达式为:
=Sum(IIf(Fields!fruit.Value <> "NonFruit", Fields!units.Value, 0))
/ Sum(IIf(Fields!fruit.Value <> "NonFruit", Fields!units.Value, 0), "FruitDataSet")
Run Code Online (Sandbox Code Playgroud)
这给出了我认为正确的结果:

该表达式有两点需要注意:
Sum通过针对表达式运行IIf,您可以控制总计中包含的内容 - 此处我将NonFruit显式设置为0。
通过设置聚合表达式的范围,您可以获得总体总计,用于计算总百分比 - 在报告中,我使用FruitDataSet获取总计,并将其与组级别总计进行比较以获得百分比值。
您引用文本框总计的方式很好;唯一的其他选择是每次需要总计时使用表达式 - 如果这是在 Tablix 之外,则需要显式设置范围,例如数据集。