Mismatched aggregation with max and sum

I want to have a field where it would take the max of the subsrciption revenue if the companies are 7620 or 7641 else it would take the sum of the subsrciption revenue but I get the Mismatched aggregation error.
how to write this?

ifelse( in({company_id},[7620, 7641]), max({subscription_usd_revenue}, [{company_id}]), 
    sum({subscription_usd_revenue}, [{company_id}]))

Hi @pantelis,
The problem with your calculated field is that it is trying to access the field “company_id” in an unaggregated manner, while aggregating the subscription revenue. It would be helpful if you could create an anonymized example on the Quick Sight Arena using some sample input data and telling us how the expected output should look like. Sharing this with the community makes it easier to support calculated field related questions. Thanks in advance.

Hello @pantelis

It has been awhile since we have heard from you so this topic is being archived.

If you still need help or have a new question please create a new topic.