2012-03-27 67 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