syntax - 正确需要嵌套 IIF 或 SWITCH 语句语法

标签 syntax reporting-services nested switch-statement

有人可以告诉我 SSRS 的这个公式中缺少什么吗?或者更好的是有人可以用嵌套 IIF 语法写同样的东西吗?

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

编辑 2:

找出了哪里不正确。

我的整个逻辑是不正确的,无法得到我期望的结果。很明显,在我的例子中,无论我使用什么,无论是 IIF 还是 switch,都只会执行第一个语句,因为它是正确的。

但是我必须改变逻辑才能得到我想要的结果。

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

这解决了我的问题。谢谢大家,我很感激。

最佳答案

尝试使用单独的 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
    )

关于syntax - 正确需要嵌套 IIF 或 SWITCH 语句语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9898575/

相关文章:

ruby-on-rails - Haml 语法 : split a line to a couple of rows

powershell - SSRS 和 powershell : Parameter not accepted

bash - shell脚本中的嵌套命令和管道命令

python - 根据逻辑表达式计算嵌套列表的所有组合

python - 如何使用嵌套字典替换其他列中的字符串

mysql - LOAD INFILE 语法错误

python - 我以前从未见过的语法错误

reporting-services - 报告修改后我会失去订阅吗?

c# - 在服务中从 C# 中的文件加载 SSRS 报告

ios - 调用单例方法 iOS 时出现预期标识符错误