Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
645 views
in Technique[技术] by (71.8m points)

reporting services - Nested IIF or SWITCH Statement syntax needed correctly

Can somebody please tell me what I am missing in this formula in SSRS? Or better yet can somebody please write this same thing in a NESTED IIF syntax?

Switch(
    (Parameters!StartMonth.Value <= 1 And Parameters!EndMonth.Value >= 1), 
     (Code.CalculateFraction(
                             (Fields!retail1.Value -Fields!cost1.Value) , Fields!cost1.Value 
                            ) *100
     ), 
    (Parameters!StartMonth.Value <= 2 And Parameters!EndMonth.Value >= 2),
     (Code.CalculateFraction(
                               (
                                 (Fields!retail1.Value +Fields!retail2.Value)- 
                                 (Fields!cost1.Value + Fields!cost2.Value)
                               ) , 
                             (Fields!cost1.Value + Fields!cost2.Value)
                            ) *100
     )
   )

This is seriously driving me crazy. For simplicity I have just put 2 iterations here. I have 12 of these and every next step I have to sum up retail1 until retail12 and cost1 until cost12.

I cant get it right for these two in the first place.

EDIT:

I am trying this now and still returns the value in the first condition

=iif(
        Parameters!StartMonth.Value <= 1 AND Parameters!EndMonth.Value >= 1,
        ReportItems!txtTotal2.Value,
        iif(
        Parameters!StartMonth.Value <= 2 AND Parameters!EndMonth.Value >= 2,
        ReportItems!txtTotal3.Value,
            iif(
            Parameters!StartMonth.Value <= 3 AND Parameters!EndMonth.Value >= 3,
            ReportItems!txtTotal4.Value,
            Nothing
               )
           )
    )

EDIT 2:

FIGURED OUT WHAT WAS INCORRECT.

My entire logic was incorrect to get to the result that I was expecting. It was obvious in my case that whatever I use, be it IIF or switch only the first statement would execute because it was true.

But I had to change the logic to get to the result that I wanted.

iif(
        Parameters!EndMonth.Value = 1,
        ReportItems!txtTotal1.Value, 
                  Parameters!EndMonth.Value = 2,
              ReportItems!txtTotal2.Value,
             and so on
            )

This solved my problem. Thanks guys I appreciate it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Syntax looks correct at first glance. Most places in SSRS you are required to have = to start your statement. Your code above refers to embedded code for CalculateFraction() Does that exist and is it used successfully elsewhere?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...