2012-03-27 146 views
2

有人可以告诉我我在SSRS中的这个公式中缺少什么吗?或者更好的是,有人可以用NESTED IIF语法编写这个相同的东西吗?需要正确嵌套的IIF或SWITCH语句语法

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 
    ) 
    ) 

这真是让我发疯。为了简单起见,我在这里只做了2次迭代。我有12个这样的下一步,我必须总结零售1直到零售12和成本1直到成本12。

我无法为这两个人摆正。

编辑:

我现在想这一点,仍然返回的第一个条件

=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的值:

想通了什么不正确。

我的整个逻辑是不正确的,以达到我期待的结果。在我的例子中很明显,无论我使用什么,无论是IIF还是只切换第一条语句,因为它是真的。

但我不得不改变逻辑来得到我想要的结果。

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

这解决了我的问题。谢谢你们,我很欣赏它。

+0

你得到一个错误,或者只是不正确的结果? – 2012-03-29 14:17:59

回答

1

尝试使用分离IIF声明:

=iif(
    Parameters!StartMonth.Value <= 1 AND Parameters!EndMonth.Value >= 1, 
    ReportItems!txtTotal2.Value, Nothing 
    ) OR 

iif(
    Parameters!StartMonth.Value <= 2 AND Parameters!EndMonth.Value >= 2, 
    ReportItems!txtTotal3.Value, Nothing 
    ) OR 

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

语法看起来正确。 SSRS中的大多数地方您都必须有=才能开始您的声明。上面的代码是指CalculateFraction()的嵌入代码是否存在并在其他地方成功使用?

+0

我正在使用=号并在我的报告中的大多数地方使用了CalculateFraction方法,并且工作正常。我没有收到任何错误。多数民众赞成在混淆我。 – aMazing 2012-03-29 21:59:53

+0

你为什么认为你的Switch语句不起作用?请给出一些输入和期望输出的例子。 – 2012-04-02 02:31:53