Raffaella Gozzini
02/06/2024, 12:15 PMJoseph Heun
02/06/2024, 1:06 PMJoseph Heun
02/06/2024, 1:06 PMRaffaella Gozzini
02/06/2024, 2:25 PMMichal Hauzírek
02/06/2024, 2:25 PMSELECT AVG({fact/quiz_attempts.attempt_number}) WHERE {label/quiz_attempts.passed} = true
This should give you average attempt # across all passed tests.
If you don’t have the attempt number in your data, you might try to construct it within MAQL (assuming you have some reliable sequential ID or a date of the attempt). Basically we want for each user and each quiz (if there are more quizzes) mark each of their attempts to pass this quiz. Assuming we have a reliable sequential ID as a fact in the data {fact/idfact}
(bigger value of ID means the test was taken later). Then something like this can work:
SELECT AVG(
SELECT (
SELECT ROW_NUMBER( {fact/idfact} ) WITHIN {label/quiz_attempts.user_name}, {label/quiz_attempts.quiz}, ALL OTHER
) HAVING {label/quiz_attempts.passed} = "true"
)
the very inner metric uses the idfact to calculate the order of attempt within quiz and user. The metric above filters it to just the passed attempts with HAVING instead of WHERE to prevent passing the filter also to the inner metric. And the level above is just an AVG of this.
If instead of sequential ID you have a date, you can do a similar thing with it. Just I believe the ranking function does not work with dates currently, so you might need to use DATE_DIFF and deduct your date from some fixed date in the past to get some numerical value to work with.
If users can take quizzes after they pass one, there would need to be some modifications to the metric. (i.e. do MIN(attempt_number) BY user,quiz before doing the AVG).Raffaella Gozzini
02/06/2024, 2:37 PMMichal Hauzírek
02/06/2024, 2:38 PMRaffaella Gozzini
02/06/2024, 2:40 PMMichal Hauzírek
02/06/2024, 2:55 PMRaffaella Gozzini
02/06/2024, 3:44 PM{
"title": "Bad Request",
"status": 400,
"detail": "A result cache error has occurred during the calculation of the result",
"resultId": "18f646d021c32c670408d480a9a4098468a9eec0",
"reason": "Window function for ROW_NUMBER with a RANGE from UNBOUNDED PRECEDING is not implemented in Redshift",
"traceId": "5fdb7557e7ca6b6c84a5d4487763f35a"
}
The metric is SELECT AVG(
SELECT (
SELECT ROW_NUMBER( {fact/quizattemptid} ) WITHIN {label/fullname}, {label/quiz_attempts.id}, ALL OTHER
) HAVING {label/quiz_attempts.passed} = "true"
)Michal Hauzírek
02/06/2024, 8:12 PM{label/quiz_attempts.quiz}
was meant as ID of the quiz, not an attempt (i.e. if there can be multiple different quizzes each user can take and pass). If you do not have multiple quizzes in your data and each user only takes one common quiz and has multiple attempts, you can just keep WITHIN {label/fullname}, ALL OTHER
I am not sure if any of these potential changes will lead to different (and working) underlying query, but I wanted to check it just in case.Michal Hauzírek
02/06/2024, 8:41 PMMichal Hauzírek
02/07/2024, 3:29 PMRaffaella Gozzini
02/08/2024, 10:29 AMMichal Hauzírek
02/12/2024, 6:00 PMRaffaella Gozzini
02/12/2024, 6:09 PM