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

如何在Tableau的SAP HANA SQL中自动传递当前年份占位符参数

Solution for Passing Current Year to HANA Query in Tableau

Hey there, let's work through this since you need to dynamically pass the current year to your SAP HANA query embedded in Tableau—no HANA Studio or dynamic SQL hacks allowed. Here's a straightforward approach that leverages Tableau's native functions to inject the current year directly into HANA's placeholder parameter:

Step-by-Step Implementation

  1. Grab the current year with Tableau's built-in function: YEAR(TODAY()) calculates the current year at runtime, so it updates automatically every time the query runs.
  2. Inject the value into HANA's PLACEHOLDER clause: Tableau resolves its own functions first before sending the final SQL to HANA, so we can directly embed this function in the placeholder assignment.

Example Custom SQL for Tableau

SELECT
    sum("StockInQualityInspection") AS in_quality,
    sum("StockInTransit") AS its
FROM "_SYS_BIC"."stream.models.marketing.poly/InventoryQuery" (
    'PLACEHOLDER' = ('$$IP_Year$$', CAST(YEAR(TODAY()) AS VARCHAR(4)))
)

(Note: Replace $$IP_Year$$ with the exact placeholder parameter name from your HANA calculation view—your original snippet had $$IP... so adjust this to match your model's actual parameter.)

Key Notes

  • Adjust for parameter type: If your HANA placeholder expects an integer instead of a string, skip the CAST and use the function directly:
    'PLACEHOLDER' = ('$$IP_Year$$', YEAR(TODAY()))
    
  • Validate first: Test by temporarily replacing YEAR(TODAY()) with a hardcoded year (like 2024) to confirm the query returns the expected results, then switch back to the dynamic function.
  • Automatic freshness: Tableau recalculates YEAR(TODAY()) every time the query executes, so your dashboard will always use the current year without manual updates.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:37:14