如何在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
- 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. - 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
CASTand use the function directly:'PLACEHOLDER' = ('$$IP_Year$$', YEAR(TODAY())) - Validate first: Test by temporarily replacing
YEAR(TODAY())with a hardcoded year (like2024) 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
相关产品推荐
相关产品推荐

