rdlc expression iif use?
Asked Answered
S

6

13

In an rdlc report I want to compare integers like

if(expression)
{
     // do something
}
else if(expression)
{
     // do something else
}

What is the syntax for this?

Scolopendrid answered 16/6, 2009 at 6:39 Comment(0)
T
46

Rather than using nested IIF statements I prefer the Switch statement.

From the MSDN...

=Switch(
    Fields!PctComplete.Value >= 10, "Green", 
    Fields!PctComplete.Value >= 1, "Blue", 
    Fields!PctComplete.Value = 1, "Yellow", 
    Fields!PctComplete.Value <= 0, "Red"
    )

Hope it helps :)

Township answered 16/6, 2009 at 6:51 Comment(2)
Thanks it's work Now i have another problem hope you help me ... I have three type board LIKE:GOOD,REMOVED,NOTFOUND.....i want a report on rdlc that show me Board type amount like below Thana Good Removed NotFound A 5 2 4 B 4 1 0 how can i do thatScolopendrid
I'm not totally sure what you mean? Can you rephrase the the question in any way, your example has lost its formatting because its a comment.Township
S
9

You will have to nest IIF statements like this:

 = IIF (expression = 1, "Is 1", IIF (expression = 2, "Is 2"))
Strephonn answered 16/6, 2009 at 6:44 Comment(2)
thannks now if i want to compare string then? what i do.... like int Total=0 if(expression=="Good") then TotalIncreaseScolopendrid
You cant have variables in that sense. You would nest the 'IIF' within a SUM or some other kind of aggregate function... =Sum(IIF(expression = "Good", 1, 0)). Something along those lines.Township
T
2

Use switch instead. I know I reached late here,but hope that it may help someone.

=Switch(Fields!Parameter.value = 2,"somethingnew", 1=1 ,"somethingelse")

1=1 refers to default in switch case.

It is similar like

if(Parameter.Value == 2)
{
somethingnew
}
else
{
somethingelse
}
Tacit answered 11/7, 2016 at 8:22 Comment(0)
R
1

This is the Syntax for your requirement:

=IIf(CInt(Fields!expression1.value)==1,true,IIf(Cint(Fields!expression2.value)==2,true,nothing))

In true part you can specify the statement to be executed.

Rosel answered 12/8, 2013 at 12:40 Comment(0)
A
1

In addition to what has been said, the If(condition, true_part, false_part) ternary operator should (with one I) be preferred over the IIf(condition, true_part, false_part) function (with two I's) in most cases.

The If() ternary operator will short-circuit evaluate only the part that corresponds to condition outcome (e.g. a condition that is True will only evaluate the true_part).

The IIf() function will always evaluate the condition and both parts, because it is just a function call and all parameters of the function will be evaluated before the call.

Since developers usually expect short-circuit evaluation in IF statements, the usage of the If() ternary operator should be the default choice. It allows you to run expressions that check for Nothing, like the following, which would not work without lazy evaluation:

=If(Fields!Blog.Value IsNot Nothing, Fields!Blog.Value.Name, "Blog is missing")
Anthropoid answered 6/3, 2021 at 22:21 Comment(0)
B
0

You could also try this example

= IIF(Parameters!expression.Value = True, 'somethingnew', 'somethingelse')

Brunildabruning answered 16/11, 2018 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.