2 Replies Latest reply on Aug 8, 2018 12:53 AM by Ankit Bansal

    Generating a calculated field using subquery

    mrs. xyz

      Greetings everyone, I want to ask how to generate a calculated field from subquery. So, I have this one subquery that I want to put on calculated field. Here is the subquery:

      select sum(amount) from (

      select amount, loan from X

      where type = 'A'

      group by amount, loan) abc;

       

      And here's my calculated field on tableau:

      {FIXED [Amount], [Loan] :

      AVG(IF [Type] = 'A'

      THEN

      [Amount]

      ELSE NULL

      END

      )}

       

      It gave me different results from the subquery above. It gave me different results when I used and not used subquery for the query on postgreSQL and the right query is the one that used subquery. Does anyone know the solution? Thank you!

       

      edit: closed! I just put another fixed and it solved the problem!