简体   繁体   中英

how to write an expression in SSRS to filter data

I need to filter my result based on Parameter value. If it says "Open" then DueDate column should be = NULL, if says 'Closed' that DueDate = NOT NULL , and if it says "Both" then it should grab all DueDate s

I have created query parameter "Status" that gives me 3 possible values:

在此处输入图像描述

Next I created report parameter "Status" and Allow Multiple Values

在此处输入图像描述

Now I go to my main query and go to Filters:

在此处输入图像描述

And here I cant understand how can I write an expression saying:

If report "status" value = "Open" then show me the result where DueDate IS NULL, If report "Status" value = "Closed" then DueDate IS NOT NULL, And If report "Status" value = "Both" then show me all DueDates ( null and not null)

Another thing is I already have case statement in my query:

ALTER Procedure
AS
@ShowOpen bit = 0,
@ShowClosed bit = 0
 SELECT
 FROM 
 WHERE 
              AND
                        (
                        (CASE WHEN (@ShowOpen = 1) THEN
                              CASE WHEN (tblNoteRecipients.CompletedDate IS NULL and tblNoteRecipients.IsDiary = 1) or tblNoteRecipients.UserGUID is null THEN 1 ELSE 0 END
                             -- CASE WHEN (tblNoteRecipients.CompletedDate IS NULL) THEN 1 ELSE 0 END
                        ELSE
                              1
                        END = 1)
                  AND
                        (CASE WHEN (@ShowClosed = 1) THEN
                              CASE WHEN (tblNoteRecipients.CompletedDate IS NULL) THEN 0 ELSE 1 END
                        ELSE
                              1
                        END = 1)
                  OR    ((@ShowOpen = 1) AND (@ShowClosed = 1))
                        )

Is any way out of it in SSRS I can create parameter that accepts values Open, Closed and Both?

Added test1

在此处输入图像描述

Add a Filter in the tablix like this:

在此处输入图像描述

In Expression use:

=IIF(
(Array.IndexOf(Parameters!Status.Value,"Open")>-1 and 
Isnothing(Fields!DueDate.Value)) or
(Array.IndexOf(Parameters!Status.Value,"Closed")>-1 and not 
Isnothing(Fields!DueDate.Value)) or
(Array.IndexOf(Parameters!Status.Value,"Both")>-1),
 "Include","Exclude")

For Value use:

="Include"

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