简体   繁体   English

Report Builder 3.0如何在不同的列上进行过滤

[英]Report Builder 3.0 How to filter on different columns

I have a parameter in my report (Report Builder 3.0) called REPORT_FILTER. 我的报表(Report Builder 3.0)中有一个名为REPORT_FILTER的参数。 This parameter has 4 available values. 此参数有4个可用值。 The labels are (1) Home Group, (2) Home Branch, (3) Other Group, and (4) Other Branch. 标签为(1)家庭组,(2)家庭分支,(3)其他组和(4)其他分支。 The corresponding values are 1, 2, 3, and 4. 相应的值为1、2、3和4。

The SQL used to run this report adds "1" to the "Filter1" column for the Home Group and "2" to the "Filter1" column for the Other Group. 用于运行此报告的SQL在本地组的“ Filter1”列中添加“ 1”,在其他组的“ Filter1”列中添加“ 2”。

The SQL used to run this report adds "1" to the "Filter2" column for the Home Branch and "2" to the "Filter2" column for the Other Branch. 用于运行此报告的SQL将“ 1”添加到Home分支的“ Filter2”列中,将“ 2”添加到其他分支的“ Filter2”列中。

When the SQL runs, I get 1 or 2 in the "Filter 1" and "Filter 2" columns. 运行SQL时,在“过滤器1”和“过滤器2”列中得到1或2。 This data is just what I expect. 这些数据正是我所期望的。

What I would like to do is add a filter to the report so the user only gets the records they want. 我想做的是在报表中添加一个过滤器,以便用户仅获得他们想要的记录。 What I'm struggling with is that the filter(s) will have to use 2 columns and I'm not sure how to do that. 我正在努力的是,过滤器将必须使用2列,但我不确定该怎么做。

For example, if the user selects, Home Group (value = 1), the report should only return those records that have a 1 in the Filter1 column 例如,如果用户选择家庭组(值= 1),则报告应仅返回在Filter1列中具有1的那些记录。

If the user selects, Other Branch (value = 4), the report should only return those records that have a 2 in the Filter2 column 如果用户选择“其他分支”(值= 4),则报表应仅返回在Filter2列中具有2的那些记录。

This report already takes a while to run several minutes, so (I think) I would prefer to filter the results in Report Builder instead of with the SQL. 该报告已经需要一段时间才能运行几分钟,所以(我认为)我希望在Report Builder中而不是在SQL中过滤结果。 If I could do it with SQL, that would be acceptable. 如果我可以使用SQL做到这一点,那将是可以接受的。 I've tried to write SQL to do this but haven't been able to succeed as well. 我尝试编写SQL来做到这一点,但还没有成功。

Any suggestions would be appreciated. 任何建议,将不胜感激。 Thanks for the help. 谢谢您的帮助。

Pretty easy to do in SQL, just add this WHERE condition: 在SQL中非常容易做到,只需添加以下WHERE条件:

WHERE 
CASE 
WHEN
   @REPORT_FILTER = 4 and Filter2 = 2 then 1
WHEN
   @REPORT_FILTER = 3 and Filter2 = 1 then 1
WHEN
   @REPORT_FILTER = 2 and Filter1 = 2 then 1
WHEN
   @REPORT_FILTER = 1 and Filter1 = 1 then 1
ELSE 0
END = 1

And similarly in SSRS, just use a Filters expression of 同样在SSRS中,只需使用Filters表达式

(Parameters!REPORT_FILTER.Value = 4 And Fields!Filter2.Value = 2)
OR
(Parameters!REPORT_FILTER.Value = 3 And Fields!Filter2.Value = 1)
OR
(Parameters!REPORT_FILTER.Value = 2 And Fields!Filter1.Value = 2)
OR
(Parameters!REPORT_FILTER.Value = 1 And Fields!Filter1.Value = 1)

Set the expression type to Boolean and set the comparison value to True. 将表达式类型设置为布尔值,并将比较值设置为True。

在此处输入图片说明

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

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