Reputation: 2163
I currently have two text box. One is to display the first value in my column called principal. The second textbox is to display a text, if the value is equal to zero, display "The principal is zero" else display "The Principal value is not zero". X being the principal amount.
The first textbox populates fine using
=First(Fields!Principal.Value, "PaymentInfoDTO")
The second textbox produces #Error using
=Switch(First(Fields!Principal.Value, "PaymentInfoDTO") = 0, "The Principal is zero", "The Principal is not zero")
First(Fields!Principal.Value, "PaymentInfoDTO") Produces 100000.
May I ask how do I fix my switch statement so it stops displaying #Erorr
Upvotes: 1
Views: 72
Reputation: 2565
The syntax you are using is correct for the IIF operator. Since you are only doing one comparison use that instead and it should work.
Edit: In response to your comment, If you want the false part of the expression to show the actual value, you would do the following:
=IIF(First(Fields!Principal.Value, "PaymentInfoDTO") = 0, "The Principal is zero", "The Principal is "+ CStr(First(Fields!Principal.Value, "PaymentInfoDTO")))
However, you could just get rid of the IIF statement altogether and make the expression:
"The Principal is "+ CStr(First(Fields!Principal.Value, "PaymentInfoDTO"))
And always show the value of PaymentInfoDTO.
Upvotes: 1
Reputation: 772
You do not have a switch statement there. Given the structure of your expression it would be best suited as an IIF()
=IIF(condition to evaluate, result if true, result if false)
=IIF(First(Fields!Principal.Value, "PaymentInfoDTO") = 0, "The Principal is zero", "The Principal is not zero")
A switch statement on the other hand only returns one result per condition checked.
=switch(condition,result if true, condition2, result if 2 is true)
You could reformat your expression to use a switch by doing this.
=Switch(First(Fields!Principal.Value, "PaymentInfoDTO") = 0, "The Principal is zero",
First(Fields!Principal.Value, "PaymentInfoDTO") <> 0, "The Principal is not zero")
Switch statements are generally best used when you have a number of values to evaluate individually. Not really the best for simple boolean returns such as checking if something is equal to 0 or not.
Upvotes: 3