简体   繁体   中英

Report Builder 3.0 How to filter on different columns

I have a parameter in my report (Report Builder 3.0) called REPORT_FILTER. This parameter has 4 available values. The labels are (1) Home Group, (2) Home Branch, (3) Other Group, and (4) Other Branch. The corresponding values are 1, 2, 3, and 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.

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.

When the SQL runs, I get 1 or 2 in the "Filter 1" and "Filter 2" columns. 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.

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

If the user selects, Other Branch (value = 4), the report should only return those records that have a 2 in the Filter2 column

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. If I could do it with SQL, that would be acceptable. I've tried to write SQL to do this but haven't been able to succeed as well.

Any suggestions would be appreciated. Thanks for the help.

Pretty easy to do in SQL, just add this WHERE condition:

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

(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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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