# Qlik Sense App Development

Contributor

## Use Aggr function twice in calculation?

Hello community,

Can I use the Aggr function twice within the same calculation?

Ex: Avg(Aggr(Count(Aggr(If...,Field))))

Note: Message was edited by Community Moderator for clarity.

Tags (3)
22 Replies
MVP

Yes, you can.

MVP

## Re: Use Aggr function twice in calculation?

Depends on what you are trying to do. If you want to know if the syntax is allowed, yes it is. But what exactly do you need this for? May be share a sample with your expected output

Contributor

## Re: Use Aggr function twice in calculation?

Ahh, I thought it was wrong and could not be used 2 times, as it gave me error, invalid function. I'll keep trying and if not inform you and explain the function and related fields.

Thanks you.

MVP

## Re: Use Aggr function twice in calculation?

Maybe we can help you better if you post the full expression.

Advanced aggregation always shows a single expression and one or more dimension fields as arguments to aggr() function.

Contributor

## Re: Use Aggr function twice in calculation?

Hi swuehl,

Step formula here where I have the inchoerencia: Avg (Aggr (Count (Aggr (If (Sum (VALO)> 0, DOC_CLI), DOC_CLI)) * COUNT (DISTINCT DATE))).

So yes I instead works: Count (Aggr (If (Sum (VALO)> 0, DOC_CLI), DOC_CLI)) * COUNT (DISTINCT DATE)

I need to average this.

This is why we consult them if they could include two Aggr, how can I fix it?

MVP

## Re: Use Aggr function twice in calculation?

Have a look at

Average – Which average?

So, what is the internal grouping entity in your case?

Contributor

## Re: Use Aggr function twice in calculation?

Hi Sunny, Step formula here where I have the inchoerencia: Avg (Aggr (Count (Aggr (If (Sum (VALO)> 0, DOC_CLI), DOC_CLI)) * COUNT (DISTINCT DATE))).

So yes I instead works: Count (Aggr (If (Sum (VALO)> 0, DOC_CLI), DOC_CLI)) * COUNT (DISTINCT DATE)

I need to average this.

This is why we consult them if they could include two Aggr, how can I fix it?

Contributor

## Re: Use Aggr function twice in calculation?

I hope to be more explanatory, you can not clearly see the solution in the link you shared me.

MVP