Good morning,
I currently have a dataset being created from our Qualtrics connector that counts the number of surveys and averages scores from specifi questions in a given time period. The time period we go off of would be between the Last Day of the Quarter (Period End) and 180 days before the Last Day of the Quarter (Period Begin.) Below is my code I am using in the ETL process:
SELECT
`Agent` ,
U.`Position`,
U.`BranchDescription`,
(ADDDATE(`LastDayOfQuarter`, -180)) AS MinDate,
(`LastDayOfQuarter`) AS MaxDate,
COUNT(DISTINCT `Response ID`) as SurveyCount,
AVG(CASE WHEN `Question ID` = 'Q1_2' THEN `Answer Value` END) AS EngagedScore,
AVG(CASE WHEN `Question ID` = 'Q1_3' THEN `Answer Value` END) AS KnowledgableScore,
AVG(CASE WHEN `Question ID` = 'Q1_6' THEN `Answer Value` END) AS ValuedScore
FROM `qualtrics_responses`
LEFT JOIN `date` D
ON (D.`Date`) = (DATE(`End Date`))
LEFT JOIN `users` U
ON U.`UserID` = `Agent ID`
WHERE `Agent` IS NOT NULL
AND DATE(`End Date`) <= (`LastDayOfQuarter`)
AND DATE(`End Date`) >= (ADDDATE(`LastDayOfQuarter`, -180))
GROUP BY `Agent`, (ADDDATE(`LastDayOfQuarter`, -180))
I have run into an issue where if the Agent does not have any surveys this year, my query is not creating the results for the current range of 10/03/2019 - 03/31/2020. I have tried a few different ways starting with my Date table but cannot seem to figure out a way that works. I know the issue stems from the way I am joining to my date table, but again, I have hit a wall and am hoping to find some answers here. Thank you in advance!