Search code examples
sqlsql-serverreporting-servicesssrs-2008

How to filter records based on a range in SSRS?


Though this question has been asked, the scenario for all such questions were totally different and didn't answer my question hence asking a new question.

I have hard coded a SQL code in SSRS query field. One of the column is from a

 CASE STATEMENT

CASE WHEN (Amt_Requested > 0) 
THEN Amt_Requested ELSE Amt_Committed END AS Final_Amount

I want to add a filter for this column where I want records BETWEEN 25000 to 50000

I tried to create an expression on the Design page of SSRS

=iif(Fields!Final_Amount.Value >=25000 AND Fields!Final_Amount.Value <= 50000,Fields!Final_Amount.Value,0)

This satisfies the condition but doesn't filter the data.

I also tried adding a FilterExpression from tablix properties, but it gives an error stating

'Please check the data type returned by the FilterExpression

PL note: The CASE STATEMENT is in SELECT STATEMENT


Solution

  • In the Tablix Filters definition, I would change the data type to Boolean, leave the Operator as =, and set the Value to True.

    Then I would set the Expression to return a True/False result as you intially described.

    This design is much more flexible as you can easily combine multiple fields, parameters etc in the one Expression. It also avoids the fragility and obscurity of datatype conversions in SSRS.