I have a question that groups on two columns in a table (MySQL) and gets a simple row count. It also has a Sum calculation of a custom column that uses a Case() to return 0 or 1 based on a condition. What I'm trying to do is get the percentage that the Sum of the Case() is of the total Count(). My custom column with the Case() is called "Qualified", and my percentage Summarize expression looks like this:
Sum([Qualified]) / Count()
When I attempt to visualize the question, I get an error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'double) / NULLIF(CAST(COUNT(*) AS double), 0.0) AS
QualifiedPercentage
FROM (S' at line 2
If I look at the SQL generated by the question, I see that it attempts to cast both numbers to double and check for a null on the Count(). If I copy the generated SQL and directly query the database, it fails with the same error. If I remove the CASTs from the SQL, it runs correctly.
How can I instruct Metabase not to CAST?