简体   繁体   中英

Error retrieving data in IIF expression with multiple conditions in SSRS

I'm new to SSRS and I'm having issues with a report that I'm creating. Maybe I'm just not understanding how the data is retrieved from the DataSet, but with a results set like this:

Count   ColA        ColB        ColC
1       Business    Start       Regular
4       Global      Middle      Regular
5       Online      Middle      Regular
8       Online      End         Regular
13      Online      Start       Regular

my assumption is that I should be able to use an expression like this

=iif(Fields!ColA.Value = "Online" AND Fields!ColB.Value = "Start" AND Fields!ColC.Value = "Regular", Fields!Count.Value, 0)

in a textbox and it should return 13. Instead it's returning the false condition of zero.

Any help that you can offer in this would be appreciated. I'm sure the answer is out there but my limited knowledge of SSRS may be hampering my search criteria skills.

答案是这样嵌套您的IIf:

=IIf(Fields!ColA.Value = "Online", IIf(Fields!ColB.Value = "Start", IIf(Fields!ColC.Value = "Regular", Fields!Count.Value, 0), 0), 0)

I figured out my problem.

When I created my Tablix, I added a bunch of rows and columns manually to show the data and in doing that removed the rows and columns that were linked to the DataSet (not sure how I did that).

My fear was being unable to show all possible output (ie rows with a count of zero needed to be shown). I reworked my query to include zero entries and recreated the report with the new query and voila, all things solved.

I know I shouldn't feel bad about being a noob, but seriously, uh-duh.

I don't have an active SSRS installation to try this out, but what happens if you add parentheses around each clause?

=iif((Fields!ColA.Value = "Online") AND (Fields!ColB.Value = "Start") AND (Fields!ColC.Value = "Regular"), Fields!Count.Value, 0)

FYI, handy documentation: https://msdn.microsoft.com/en-us/library/ms157328.aspx .

I recall now that I usually moved this kind of logic into the SQL query, which can make debugging easier and even facilitates unit testing. For example, you could add one more field in your select statement, with something like:

SELECT CASE WHEN ColA == 'Online' AND 
                    ColB == 'Start' AND
                    ColC == 'Regular'
            THEN [Count]
            ELSE 0 END as ColD,

And now you can simply refer to ColD in SSRS.

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