If we sum the ‘Time’, and divide by the sum of ‘Item’, we have: 95 / 3 = 31.6 (which is the average I’m looking for).
If I just do the usual Scriptcase Avg on Time, it divides the 95 sum by the total count of records (5), giving an average of 19 - which is not correct.
Sum don’t count records, sum values.
As you mentioned, the ‘On Record’ doesn’t like dividing by zero…but I ‘believe’ the formula you’re suggesting would ignore the record completely if the Item = 0…however I can’t ignore the Time associated with that 0 record - I need all the Time totaled for the month (thousands of records) and divided by the sum of the field ‘Item’.
Was just an example. I understood you want to do your formula on every record.
Did I completely misunderstand what your previous post is referencing, or did I not explain myself properly the first time? I can do it in straight SQL code just fine, and it seems like it should be simple to do based on everything Scriptcase can do, but I just can’t seem to grasp how to get this done. Sorry for being a noob.
Because maybe I don’t understood correctly. I don’t know either if you want to show this value on a alert, or what, otherwise.
One option is using the Totals propertys of the Grid, as Sum for Item and Time, and then, onFooter event, you can access the value with special summary vars {sum_(your field)}, in your example {sum_item} and {sum_time} , then you just have to do something like:
$average = {sum_time}/{sum_item}
sc_alert ($average);
Another option is to have 2 global vars (set it as out), [glo_time] and [glo_item] and in your onRecord event do.
[glo_time] += {time};
[glo_item] += {item};
Once grid is loaded you will have in this 2 global variables all time and items to do your calcs.
As I mentioned, I don’t know exactly where you want to show this value or what do with it, I’m just “blind” telling you different ways to get the value you want