Are there any tools for aggregating results by product rather than sum or avg?

Can you be more specific? Personally Iâ€™m not sure what you mean. Product?

The same way that sum() or avg() are applied to a collection of variables, is there a way to evaluate the product of a collection of variables as well?

For example:

SUM([a b c]) = a+b+c

PRODUCT([a b c]) = a*b*c

PS. I still feels I did not understood.

In aggregation itself we have only `min`

`max`

`sum`

and `avg`

thereâ€™s no other func.

If you mean other thing, It will depends.

Abstract: â€śYou want to organize a result by the product of a calculation made in another query blockâ€ť

You could use something like â€ś`@filter(gt(val(PRODUCT), 60`

â€ť.

Check this example below (you can run in https://play.dgraph.io)

```
{
var(func:allofterms(name@en, "steven spielberg")) {
films as director.film {
p as count(starring)
q as count(genre)
date as initial_release_date
years as math(since(date)/(365*24*60*60))
score as math(cond(years > 10, 0, ln(p)+q-ln(years)))
}
}
TopMovies(func: uid(films), orderasc: val(years)) #@filter(gt(val(score), 2))
@filter(gt(val(years), 6) and le(val(years), 14))
{
name@en
val(score)
val(date)
val(years)
}
}
```

In my particular case Iâ€™m attempting a probability calculation using the weights (facets) of my graph with an unknown number of edges. The function Iâ€™m attempting to replicate is:

likelihood = PROD(probability)/(1-PROD(probability))

Where PROD is the math.prod function from Python and probability is the collection of probability values on the edges between nodes (facets).

So basically Iâ€™m looking how to replicate the functionality of Pythonâ€™s math.prod() function.

PS Sorry Iâ€™m new here and donâ€™t yet know how to format everything!

I did a google of it. From what I saw, I canâ€™t see youâ€™re doing that with Dgraph as far I understand Maths, aggregation and vars from Dgraphâ€™s features. Maybe someone has some idea about it.

Yeah I canâ€™t figure it out either - I was hoping someone here had an idea of how to do it.

Thanks for the input!

I think I have a work-around using logarithm rules:

```
log2(A) + log2(B) = log2(A*B)
2^log2(A) = A
```

So I can get the product of the values using sum() aggregation and the logbase() and pow() math functions:

```
log_L = log2(L)
sum_log_L = sum(log_L)
prod_L = 2^sum_log_L
```