简体   繁体   English

SQL Server报表服务和报表开发

[英]SQL Server Reporting Services and Report Development

I have four datasets, Plan, Forecast, Actual and SPLY per eight different product lines. 我每八个不同的产品线有四个数据集,计划,预测,实际和SPLY。 I want to add conditional formatting of background color if actual is above or below Plan and/or Forecast. 如果实际值高于或低于计划和/或预测,我想添加背景颜色的条件格式。 The report needs to export properly to Excel. 该报告需要正确导出到Excel。 Is there a way I can use one control rather than multiple text boxes to display the data, allow for conditional formatting and export to Excel? 有没有一种方法可以使用一个控件而不是多个文本框来显示数据,允许条件格式设置并导出到Excel? Thanks! 谢谢!

Environment: 环境:

SSRS 2010 SSRS 2010

SQL Server 2012 SQL Server 2012

Great Question Lakeshore. 大问题湖岸。 I see two possibilities: 我看到两种可能性:

  1. Join the datasets together in a single dataset so the results return Plan, Forecast, and Actual Values for each Product Line. 将数据集合并到一个数据集中,这样结果将返回每个产品系列的计划,预测和实际值。 Then you can simple set the background: 然后,您可以简单地设置背景:

     =iif(Fields!Plan.Value > Fields!Actual.Value,"Pink","LightGreen") 
  2. Use the Lookup function to reference Values from a different Dataset based on the Product Line: 使用查找功能可根据产品线引用来自其他数据集的值:

     =iif(Lookup(Fields!ProductLine.Value,Fields!ProductLine.Value, Fields!Plan.Value,"Plan") > Fields!Actual.Value,"Pink","LightGreen") 

Join your data together in your SQL statement for the report so that you get one row with product, actual, plan, forecast in the same dataset. 在报表的SQL语句中将数据连接在一起,以便在同一数据集中获得包含产品,实际,计划和预测的一行。 Then you can use an expression for the background color of the textbox that you want to conditionally format. 然后,您可以使用表达式作为要有条件格式化的文本框的背景色。

Here is an example: 这是一个例子:

=IIF(Fields!Actual.Value >= Fields!Plan.Value, "Green", "Red")

Also see this thread for more details: SSRS Field Expression to change the background color of the Cell 另请参阅此线程以获取更多详细信息: SSRS字段表达式以更改单元格的背景颜色

Or you could use a switch statement that would say if Actual is below both plan and forecast then make it red, if above or equal to both then make green, else (Actual assumed to be above one and below the other) make yellow: 或者,您可以使用switch语句,如果“实际”低于计划和预测,则将其设为红色;如果高于或等于“两者”,则将其设为绿色;否则(假定“实际”高于一个且低于另一个)则设为黄色:

=Switch(Fields!Actual.Value < Fields!Plan.Value and Fields!Actual.Value < Fields!Forecast.Value
  , "Red"
  , Fields!Actual.Value >= Fields!Plan.Value and Fields!Actual.Value >= Fields!Forecast.Value
  , "Green"
  , 1=1, "Yellow")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM