Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
Highlighted
pierreolivier
New Contributor

Dynamically using a dimension inside an aggregate (aggr)

Hi everyone , I am currently trying to change the column used in a aggregate based on a variable.

 

Here is what I have tried so far :

 

=AVG(
    	total Aggr(
        	sum(Total),
           	if(Place = 'Country', Country, State)
       )
    )

and

=AVG(
    	total Aggr(
        	sum(Total),
           	if('$(Place)' = 'Country', Country, State)
       )
    )

Where Total, Country and State are columns, and Place a variable.

Note that if I remove the If and use specifically Coutry or State, there is no problem.

I have made sure that the variable has a value.

 

Is there any way to dynamically specify the dimension in the aggregate function?

Labels (2)
1 Solution

Accepted Solutions
pierreolivier
New Contributor

Re: Dynamically using a dimension inside an aggregate (aggr)

We ended up renaming the columns to be the exact name that we used in the variables. Heres what ended up working :

=
AVG(total 
  Aggr(
    sum(Total),
    [$(Place)]
  )
)

View solution in original post

2 Replies
Digvijay_Singh
Honored Contributor III

Re: Dynamically using a dimension inside an aggregate (aggr)

Not tried but what if you try like this by moving if condition in the Place variable. - 

=AVG( total Aggr( sum(Total),'$(Place)'
) )
pierreolivier
New Contributor

Re: Dynamically using a dimension inside an aggregate (aggr)

We ended up renaming the columns to be the exact name that we used in the variables. Heres what ended up working :

=
AVG(total 
  Aggr(
    sum(Total),
    [$(Place)]
  )
)

View solution in original post