I am having problems with performance of my current calculations and I'm seeking for any help with improving it.

So the problem is I have to calculate an average of Product weight for a given date range, however in single day, product can be produced up to 3 times (3 shifts a day).

I've been trying to use PALO.DATA.AVG, however I cannot make it to work on an array of days.

What I am doing right now is I'm getting total weight from an array of days using SUM(PALO.DATAV()) and then I divide it by number of days product was manufactured per each shift (DFILTER), however in order to get a real number, I need to calculate it for each of 3 shifts separately and then sum it up.

This is how it looks like in a simplified view:

Sum(palo.datav(....,@DateRange,"Weight",....)) / (

PALO.SUBSETSIZE(..."DATE"...,PALO.TFILTER(..@DateRange...),PALO.DFILTER(...."Shift 1"...)) +

PALO.SUBSETSIZE(..."DATE"...,PALO.TFILTER(..@DateRange...),PALO.DFILTER(...."Shift 2"...)) +

PALO.SUBSETSIZE(..."DATE"...,PALO.TFILTER(..@DateRange...),PALO.DFILTER(...."Shift 3"...))

)

I'm adding that formula in a dyna range and the performance is devastating, but I can't find any other way to get the average...

I would really appreciate if someone could help me.