This article explains what to do if you are seeing an error message that says "Warning - Generated with errors: Slide x: Divide_by_zero - QueryError: division by zero."
For presentation generators (end users)
If you are an end user of Matik, contact your administrator if you encounter this issue.
For content creators (administrators)
The following error message results from a divide by zero error in Dynamic Content within a template. It occurs when the parameters of a query result in a zero in the denominator.
For example, in the piece of Dynamic Content below, we are trying to display the average page views per user for a specific company by dividing the number of views by the total number of users.
Let's imagine the input for this dynamic content is company_name = 'SimpleTicket' and no SimpleTicket users made any views. As a result, the table page_views would have zero rows when filtered on
company_name = 'SimpleTicket' ,
= 0 and
COUNT(user_id) = 0. Since most databases are unable to divide by zero, this throws a query error which is then passed to Matik.
As an administrator, you can resolve this issue by finding what Dynamic Content and parameters are creating the divide by zero error, then editing the query to handle the zero in the denominator.
In the problem above, we can resolve it by adding a
COALESCE() function to our query, as shown here:
COUNT(user_id) = 0, the
NULLIF() function will return NULL in the denominator. This prevents the divide by zero error from being thrown. The result is
/ NULL, which equals
NULL. Practically speaking, we want our query to return zero rather than NULL, so we wrap this in a
COALESCE() function to return 0 if our first calculation returns NULL.
The example above was written in Amazon Redshift. Different databases and data warehouses have slightly different SQL syntax and functionality. Refer to your data source's documentation for more information on your specific data source.