Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
pierreolivier
Contributor
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
Contributor
Contributor
Author

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

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

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

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)]
  )
)