Ssrs

在 SSRS 中使用 Switch

  • May 30, 2014

在下面的表達式中,我想評估幾件事。如果材料百分比大於 89.9%,我想將值變為紅色。如果不是,請查看以下內容。發票金額小於 75 美元且材料百分比大於 20% 時變為橙色。

=SWITCH(Fields!Matl_.Value > 89.9, "RED", Fields!IHDAR_AMT1.Value < 75 and Fields!Matl_.Value > 20, "ORANGE", Fields!IHDAR_AMT1.Value < 76 and Fields!IHDAR_AMT1.Value > 150 and Fields!Matl_.Value > 30, "ORANGE", Fields!IHDAR_AMT1.Value < 151 and Fields!IHDAR_AMT1.Value > 250 and Fields!Matl_.Value > 40, "ORANGE",  Fields!IHDAR_AMT1.Value < 226 and Fields!IHDAR_AMT1.Value > 375 and Fields!Matl_.Value > 50, "ORANGE",  Fields!IHDAR_AMT1.Value < 376 and Fields!IHDAR_AMT1.Value > 625 and Fields!Matl_.Value > 60, "ORANGE",  Fields!IHDAR_AMT1.Value < 626 and Fields!IHDAR_AMT1.Value > 850 and Fields!Matl_.Value > 67.5, "ORANGE",  Fields!IHDAR_AMT1.Value < 851 and Fields!IHDAR_AMT1.Value > 1500 and Fields!Matl_.Value > 7500, "ORANGE",  Fields!IHDAR_AMT1.Value < 1501 and Fields!IHDAR_AMT1.Value > 2500 and Fields!Matl_.Value > 80, "ORANGE",  Fields!IHDAR_AMT1.Value < 3501 and Fields!IHDAR_AMT1.Value > 4500 and Fields!Matl_.Value > 84, "ORANGE",  Fields!IHDAR_AMT1.Value < 4501 and Fields!IHDAR_AMT1.Value > 5000 and Fields!Matl_.Value > 85, "ORANGE")

我現在擁有它的方式看起來就像在看了這個之後就停止了:

=SWITCH(Fields!Matl_.Value > 89.9, "RED", Fields!IHDAR_AMT1.Value < 75 and Fields!Matl_.Value > 20, "ORANGE"

非常感謝任何幫助!

泰勒

我建議你仔細閱讀你寫的表達式,因為你的邏輯有缺陷,這就是為什麼你的SWITCH陳述沒有像你認為的那樣工作。

=SWITCH
   (Fields!Matl_.Value > 89.9, "RED", 
       Fields!IHDAR_AMT1.Value < 75 and Fields!Matl_.Value > 20, "ORANGE", 
       Fields!IHDAR_AMT1.Value < 76 and Fields!IHDAR_AMT1.Value > 150 and Fields!Matl_.Value > 30, "ORANGE", 
       Fields!IHDAR_AMT1.Value < 151 and Fields!IHDAR_AMT1.Value > 250 and Fields!Matl_.Value > 40, "ORANGE",  
       Fields!IHDAR_AMT1.Value < 226 and Fields!IHDAR_AMT1.Value > 375 and Fields!Matl_.Value > 50, "ORANGE",  
       Fields!IHDAR_AMT1.Value < 376 and Fields!IHDAR_AMT1.Value > 625 and Fields!Matl_.Value > 60, "ORANGE",  
       Fields!IHDAR_AMT1.Value < 626 and Fields!IHDAR_AMT1.Value > 850 and Fields!Matl_.Value > 67.5, "ORANGE",  
       Fields!IHDAR_AMT1.Value < 851 and Fields!IHDAR_AMT1.Value > 1500 and Fields!Matl_.Value > 7500, "ORANGE",  
       Fields!IHDAR_AMT1.Value < 1501 and Fields!IHDAR_AMT1.Value > 2500 and Fields!Matl_.Value > 80, "ORANGE",  
       Fields!IHDAR_AMT1.Value < 3501 and Fields!IHDAR_AMT1.Value > 4500 and Fields!Matl_.Value > 84, "ORANGE",  
       Fields!IHDAR_AMT1.Value < 4501 and Fields!IHDAR_AMT1.Value > 5000 and Fields!Matl_.Value > 85, "ORANGE"
   )

當您格式化程式碼時,很容易看到您編寫瞭如下子句:

Fields!IHDAR_AMT1.Value < 76 and Fields!IHDAR_AMT1.Value > 150 

的值IHDAR_AMT1.Value不能同時小於 76 和大於 150,因此它立即計算為FALSE

引用自:https://dba.stackexchange.com/questions/66199