Skip to content
Advertisement

How to assign @variables in tableau

I am trying to use the following in Tableau to declare date variables, which I later call them in the SQL code.

But I am unable to do the same in Tableau. Can you please help/guide me in the right direction to use these functions

Tableau Declare Error Message

Advertisement

Answer

I’m assuming you’re trying to use Custom SQL – you don’t actually say it but the code and the error message suggests it.

Tableau “wraps” custom SQL in a select like this:

Which is why your code isn’t working as you think it should.

Also, your parameter is hard coded within the SQL itself. I’m guessing you’re going to replace this with a Tableau parameter in due course.

So the short answer is, you can’t use DECLARE like you intend. The long answer is that without declaring the variable in SQL you just have to refer to the parameter value all the time within your custom SQL.

Try NOT to use custom SQL though, it only makes Tableau slower than what it should be because you’re forcing it to run your code when it might know that there’s a faster option.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement