KNOWLEDGE BASE

Error: "TableauSQL.1" is not valid in the context where it is used." When Using Custom SQL


Published: 24 Feb 2017
Last Modified Date: 27 Feb 2017

Issue

When using Custom SQL, an error similar to the following may occur:
"TableauSQL.1" is not valid in the context where it is used. "

Environment

  • Tableau Desktop 10.1.1
  • Windows 7
  • Custom SQL

Resolution

The aggregated columns must be aliased. See the below section, for more information.

Cause

In Tableau, custom SQL query are sent as a sub-query against the database. Because the inner table is derived, all table names and aggregations need to be aliased as well.

For example, if the below was our custom sql:
SELECT count(*) AS "a" 
FROM Table1
The following would be sent to the database:
SELECT "TableauSQL"."a" AS "a" 
FROM ( 
  select count(*) AS "a" from Table1
) "TableauSQL" 
If the column is not aliased:
SELECT count(*)
FROM Table1
An error similar to the following will occur:  "TableauSQL.1" is not valid in the context where it is used."
Did this article resolve the issue?