Analysis Services 2005 引入 KPI (關鍵效能指標) 功能,但 Reporting Services 2005 無法原生讀取 Cube 中定義的 KPI。本文提供兩種替代解決方案。
在報表專案的自訂程式碼中撰寫函式,根據 Cube 傳回的 KPI 狀態值與趨勢值,動態決定顯示的圖示檔案名稱。
Public Function GetKPI(ByVal currentValue As Integer, ByVal type As String) As String
Select Case currentValue
Case 1
Return type & "2" ' 正向趨勢圖示
Case 0
Return type & "1" ' 持平圖示
Case -1
Return type & "0" ' 負向趨勢圖示
End Select
End Function
在圖片屬性的 Value 運算式中設定:
=Code.GetKPI(Fields!Product_Gross_Profit_Margin_狀態_.Value, "cyl")
其中 type 參數指定圖示類型前綴(如 "cyl" 代表圓柱儀表),函式回傳完整檔名(如 "cyl2.png"),報表即可動態顯示對應 KPI 圖示。
若專案需高度客製化 KPI 視覺化呈現,方案二更具彈性;若需快速原型且不介意預設圖示,方案一較省時。