You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSRS报表:基于年份参数用Switch函数动态设置条形图颜色

Fix Dynamic Bar Color Based on SSRS Year Parameter

Got it, let's tweak your existing Switch expression to make the bar color respond dynamically to the selected Year parameter. Here's how to do it properly:

Updated Expression

Replace your current formula with this one in the bar chart's Fill Color expression:

= Switch(
  // Keep your existing yellow for the estimated 2020 rate
  Fields!columnName.Value = "Fluctuation Rate 2020 (Estimated)", "Yellow",
  // Match the selected year's bar and set color based on the parameter
  Fields!columnName.Value = "Fluctuation Rate " & Parameters!Year.Value, 
    IIf(Parameters!Year.Value = "2018", "Silver", "Lime"),
  // Keep 2017 as silver like before
  Fields!columnName.Value = "Fluctuation Rate 2017", "Silver",
  // Default to silver for any other unlisted bars
  True, "Silver"
)

How It Works

Let's break down the logic so you understand what's happening:

  • First, we handle the special case of "Fluctuation Rate 2020 (Estimated)" to keep it yellow, just like your original setup.
  • Next, we check if the current bar's field name matches the selected year (we dynamically build the field name using the Parameters!Year.Value).
    • If the selected year is 2018, that bar stays silver.
    • If it's 2019 or 2020, the bar switches to lime.
  • We keep the 2017 bar fixed as silver.
  • Finally, a default silver color ensures any other bars (if added later) don't end up without a color.

Quick Notes

  • If your Year parameter uses an integer data type instead of string, convert it to a string when building the field name: change "Fluctuation Rate " & Parameters!Year.Value to "Fluctuation Rate " & CStr(Parameters!Year.Value).
  • Double-check that your field names match exactly (spaces, capitalization, parentheses matter—SSRS is strict about this!).

内容的提问来源于stack exchange,提问作者Hasan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 18:52:43