Handling an empty datatable

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.

Thank you for posting your solution - helps others in community as well.

Thanks
Rashmi

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.