```NVL2( max( { item.averagecost }), ( TRUNC( ...
# suiteanalytics
k
Copy code
NVL2(
 max( { item.averagecost }),
 ( TRUNC(
    SUM(
      NVL({ amount }, 0) - NVL({ item.averagecost }, 0) * { quantity }
    ) / SUM(NULLIF({ amount }, 0)),
    2
  ) * 100),
  (TRUNC(
    SUM(
      NVL({ amount }, 0) - NVL({ item.lastpurchaseprice }, 0) * { quantity }
    ) / SUM(NULLIF({ amount }, 0)),
    2
  ) * 100)
)