Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
cfountain72
Creator II
Creator II

Dynamic Aggregation based on Field

Hello, 

I am trying to develop an expression that will aggregate based on a field value. Some of the dimensions should be averages, while other should be sums. I'm trying to do something like this, but I'm getting nulls.

=$(=Only(CalcType))(Measure)

where CalcType is a Field that is either 'Sum' or 'Avg' or 'Median', etc. which would yield Sum(Measure), or Avg(Measure), etc. (I could use If's but I worry about the performance implications as the data grows)

Any suggestions? 

Thanks in advance for your help,

Chris

Labels (2)
1 Solution

Accepted Solutions
Sayed_Mannan
Creator II
Creator II

instead of if you can use PICK and MATCH functions to achieve something like this:

here is the sample you can use:

Pick(
Match(Only(CalcType), 'Sum', 'Avg', 'Median'),
Sum(Measure),
Avg(Measure),
Median(Measure)
)

I hope this helps.

View solution in original post

2 Replies
Sayed_Mannan
Creator II
Creator II

instead of if you can use PICK and MATCH functions to achieve something like this:

here is the sample you can use:

Pick(
Match(Only(CalcType), 'Sum', 'Avg', 'Median'),
Sum(Measure),
Avg(Measure),
Median(Measure)
)

I hope this helps.

rwunderlich
MVP
MVP

If CalcType varies, you will need to use an If() in this case. 

-Rob