Skip to main content

How to write case statement on custom SQL for below.

----------------------------------------------------------------------------------------------------

Tableau Calculation field

IF [Management Cutoff day ] = 0 THEN

[RunDate] != [RunDate Parameter] or [RunDate] = [RunDate Parameter]

ELSE

[RunDate] > DATE(DATEADD('day',-[Management Cutoff day ],[RunDate Parameter]))

AND

[RunDate] <= [RunDate Parameter]

END

---------------------------------------------------------------------------------------------------

Custom SQL using where clause

---------------------------------------------------------------------------------------------------

 FROM [Analytics].[PM].[PortfolioData]

 

WHERE 

 CASE [Management Cutoff day ] = 0 THEN

when [RunDate] <>= [RunDate Parameter] or [RunDate] = [RunDate Parameter] then

rundate

ELSE

[RunDate] > DATE(DATEADD('day',-[Management Cutoff day ],[RunDate Parameter]))

AND

[RunDate] <= [RunDate Parameter]

END

 

--------------------------------------------------------------------------------------------------------

I have a requirement on custom SQLPlease suggest.

3 answers
  1. Jun 6, 2025, 11:48 AM

    As an aside, the error in your image seems to suggest Tableau can't even connect to the database, so I would probably get the query working in your database with example dates then get that working in Tableau, before replacing the parameterised elements with your parameters.

0/9000