In Canvas, i’m Using the expression editor to calculate a percentage for use in a Metric object. After creating the datatable using ply, I’m executing the line:

math “mean(percentage)”

However, if my datatable is empty, this throws an exception. Is there a way in the expression editor to check for an empty datatable and only call the math fn if the datatable is NOT empty, otherwise set the metric value to 0?

Finally figured this one out. I replaced the line:

math "mean(percentage)"

with:

if {rowCount | eq 0} then=0 else={math "mean(percentage)"}

If the datatable is not empty, then it returns the average of the "percentage" column, otherwise it returns an "average" value of 0. Now I no longer get the error triangle at runtime of the canvas.

Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.