forums

Use these forums to ask questions and discuss Tableau.

Limitations of RAWSQL functions?

I am trying to extract a value based on 2 dimensions: given a list of Condition1, Condition2, Value return Value for Condition1=C1 and every C2.

I want to use the result of this calculation to compute the ratio of Value to this reference value for each condition in Condition2 . I was trying to use RAWSQL functions for that but although the following query works

RAWSQL('select avg(%1) from "TableauExtract" where "Condition1"=%2 and "Condition2"=%3',[Value],"C1",[Condition2])

it returns the average Value over the full dataset and not by Condition2. It is also throwing an error ( "Firebird database error 335544652: multiple rows in singleton select") when I remove the avg() around %1. Is there anything I am missing here?

Many thanks in advance,

Yann

Comments

Well, RAWSQL can be difficult to use in this way. It works well if you simply use it to call functions we don't support in Tableau, trying to use it for queries is very tricky, although it is possible.

In this case, I'd guess that rather than passing [Value] for %1, you want to put in the name of the table directly in the query like:
RAWSQL('select avg("Value") from "TableauExtract" where "Condition1" = %1 and "Condition2" = %2', "C1", [Condition2])

This way the "Value" will come from the joined TableauExtract rather than the original table. When you use the [Value] column reference, it's going to insert a reference to the original table that you are joining against, which is essentially a constant in this scenario.

Syndicate content Subscribe to the comments on "Limitations of RAWSQL functions?"