I'm trying to add two new columns to a dataset, each based on certain conditions across 3 existing date columns in the input table. This either needs to be a MySQL or Magic ETL dataflow as it gets used to join with another dataset vs. directly powering a card.
Existing Columns:
'Created Date'
'Converted Date'
'Last Interesting Moment Date'
Each of these are date data types in the input dataset, using a format like Jan 1, 2019
The two new columns and logic are:
1) 'Active in 2019': if any of the 3 existing dates have a date of Jan 1, 2019 or later
2) 'Latest Active Date': the most recent value for any of the 3 existing dates
Here are my attempts in SQL, breaking the above out into two separate table transforms
1) Create the 'Active in 2019' Column:
SELECT
*,
CASE
WHEN `Created Date` > 'Dec 31, 2018'
OR `Converted Date` > 'Dec 31, 2018'
OR `Last Interesting Moment Date` > 'Dec 31, 2018'
THEN "Yes"
ELSE "No"
END AS 'Active in 2019'
FROM `sf_001a_sfdc_leads_conversions_transforms`
2) Create the 'Last Active Date' Column:
SELECT
*,CASE
WHEN `Created Date` >= `Converted Date`
OR `Created Date` >= `Last Interesting Moment Date`
THEN `Created Date`
WHEN `Converted Date` >= `Created Date` OR `Converted Date` >= `Last Interesting Moment Date` THEN `Converted Date`
WHEN `Last Interesting Moment Date` >= `Created Date` AND `Last Interesting Moment Date` >= `Converted Date` THEN `Last Interesting Moment Date`
ELSE `Created Date`
END AS 'Last Active Date'
FROM
`sf_001a_sfdc_leads_conversions_transforms`