
I have the below Microsoft SQL code which basically creates two separate tables (one with index operations and one with ECMOs) and then joins on the ID between them where the date of the the ECMO is after the date of the Index Operation to get a list of hospitalizationIDs that are post-index operation. How do I translate this to Tableau? I started trying to make a custom SQL query but was unsure how to do that and then was thinking a series of calculated fields? Not exactly sure where to start.
--create index and ECMO table
select distinct HospitalizationID, IndexOperation, SurgDt
INTO ⌗index
from ⌗export
where IndexOperation=1
group by hospitalizationID, IndexOperation, SurgDt
select distinct HospitalizationID, Mechanical_Support, IndexOperation, SurgDt
INTO ⌗ECMO
from ⌗export
where IndexOperation=0 and Mechanical_Support='ECMO'
group by hospitalizationID, Mechanical_Support, IndexOperation, SurgDt
--post index operation/surgery ECMO during same hospitalization
select distinct E.HospitalizationID, I.PrimaryPx
from ⌗ECMO E
LEFT JOIN ⌗index I
on I.hospitalizationID=E.HospitalizationID
where E.SurgDt > I.SurgDt
Hi @Camile Molina
Some ideas for you.
Firstly Tableau has the idea of initial SQL: "an initial SQL command that will run when a connection is made to the database, for example, when you open the workbook, refresh an extract, sign in to Tableau Server, or publish to Tableau Server. Initial SQL is not run when your refresh your view." - https://help.tableau.com/current/pro/desktop/en-us/connect_basic_initialsql.htm. Could you use initial SQL to populate some semi-permanent tables? The equivalent of index and ECMO essentially.
Alternatively perhaps you could use two Custom SQL connections and relate them together? So drop the INTO and use each of those first two queries as a Custom SQL and then relate them on the join.
Finally could you handle this in data prep / ETL pre Tableau (or maybe even using Tableau Prep), so that when you get to Tableau you just have an index and ECMO table already.
One other observation - you probably don't need DISTINCT and GROUP BY. The GROUP BY will essentially create the distinct combos.
Ta,
Steve.
PS. Slight caveat to all of the above: you don't specify how the original temp table is created in the queries. That might make a difference to the best approach.