enavuio
enavuio

Reputation: 1500

Turning a Tableau Calculation into a SQL Query

I am trying to validate a Tableau value through writing a SQL query but I do not feel like I understand the calculation to its fullest

The calculation is

IF      {   FIXED   Account ,  MonthYear :   MAX([type])   } = 'Upgrade' THEN    'Upgrade'
ELSE    {   FIXED   Account ,  MonthYear  :   MAX(plan)   }
END

SQL query is

SELECT 
    ACCOUNT, 
    CASE 
       WHEN MAX(type) = 'Upgrade' 
          THEN 'Upgrade'
          ELSE MAX(plan) 
    END AS plan,
    MonthYear,
    USAGE
FROM  
    table
GROUP BY 
    Account, monthyear

The number is not aligning up with the data, so I just want to make sure I am understanding completely what this tableau calculation is doing

Upvotes: 0

Views: 307

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269743

The query doesn't quite make sense. Do you intend this?

SELECT ACCOUNT, 
       (CASE WHEN MAX(type) = 'Upgrade' then 'Upgrade'
             ELSE MAX(plan)
        END) as plan,
       MonthYear
FROM table
Group by Account, MonthYear

Upvotes: 1

Related Questions