5 Replies Latest reply on Apr 16, 2018 12:40 PM by Chris Panks

    Union of several select queries of same data source

    Chris Panks

      I'm new to Tableau (10.4), and working with graphical query design. I'm working with a Redcap database through a Web Data Connector connection. Apparently, Custom SQL is not an option with this connection, as I don't see such a link anywhere. If I'm mistaken in that regard, I'd love to hear about it.


      What I want would look something like this in SQL:

      select 'The X response count is: ', count(Field_X) as response_count from my_table where Field_X is not null union

      select 'The Y response count is: ', count(Field_Y) as response_count from my_table where Field_Y is not null union

      select 'The Z response count is: ', count(Field_Z) as response_count from my_table where Field_Z is not null


      I can get just one to work, by dragging Field_X into the Marks box, and using Edit in shelf... to make it Count(Field_X). And then dragging Field_X into the Filters box, and selecting all the non-null values. And then dragging the Count(Field_X) into the Rows space. That gets me an accurate table that looks like:

      Count of Field_X: 321


      However, when I repeat that same process with Field_Y, I end up with a table that is only correct for Field_Y, like this:

      Count of Field_X: 287

      Count of Field_Y: 287


      What am I missing? Thanks in advance!