B. Clay Shannon B. Clay Shannon - 1 year ago 135
Vb.net Question

How can I test for two field values in an SSRS Textbox's Expression property?

I successfully use this Expression in a Textbox:


I need to be more granular, though - not only am I looking for a Week value of "WK1" for this particular column before assigning it the value of the Price field, but also based on the value of the Unit field.

So I would expect an expression like this to work:

=IIF((Fields!Week.Value="WK1" && Fields!Unit.Value="Rock Bottom"),Fields!Price.Value,"")

...or else this:

=IIF(((Fields!Week.Value="WK1") && (Fields!Unit.Value="Rock Bottom")),Fields!Price.Value,"")

...but when I try previewing the results after either of those, I get, "The report preview failed because the report could not be built. Read the errors, warnings, and messages in the Error List window for specific build failures."

That message is: "[rsCompilerErrorInExpression] The Value expression for the textrun ‘TextboxCraftworksPriceWk1Data.Paragraphs[0].TextRuns[0]’ contains an error: [BC30201] Expression expected."

So it says an expression is expected; how are those expressions not expressions?

Now I've got John Mellencamp's "Without Expression" tune zipping through my mind's ears.

Answer Source

From Expression Reference (Report Builder and SSRS)
Expressions must have valid Visual Basic syntax before a report can be published or processed.

With that in mind you should be using logical And operator as @alejandro-zuleta pointed out in the comments.

=IIF((Fields!Week.Value="WK1" And Fields!Unit.Value="Rock Bottom"), Fields!Price.Value, "")

Useful Links

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download