How to filter a calculated field

I’m trying to do this:

ifelse(
{tipo} = ‘pet’,
sum({receita_abs}) / sum({receita}),
null
)

But I’m getting this error:
Mismatched aggregation. Custom aggregations can’t contain both aggregated and nonaggregated fields, in any combination.

I’m just trying to do a divison beteween to calculated fields but if a already with a filter or condition, to do this division only with cases where the collumn “type” have the value ‘pet’.

Hello @LucasRoque , welcome to the Quick Sight community!

Since you haven’t used a parameter to pass the target value I’m assuming that you will not want {tipo} to be dynamic.

Rather than creating an ifelse calculation, I would recommend creating a filter on your target visual for {tipo} = ‘pet’ and then leaving your calculated field as sum({receita_abs}) / sum({receita}) .