Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
csh8428
Contributor II
Contributor II

Get average in a pivot table

How can I get the average of a dimension in a pivot table? When using the "avg" function it takes the average of the entire data-set. In this example, I'm trying to get the average tenure of for each Director's subordinate's in a pivot table. But, when I use the avg function( avg(Tenure(Mth) ) it puts the average of the entire data set into each cell next to Director. What's the expression to get the average tenure for each director's EIDs while also displaying the overall average for the entire data set like you can in a simple pivot table in excel?

I've seen lots of other posts that are similar to this and haven't been able to convert the answers to work.

 

Sample Data

EIDDirectorTenure(Mth)Tenure(Yr)
3584Smith443.7
4466Smith262.2
4071Smith00
2026Smith756.2
376Jones100.8
4053Jones373.1
3751Jones484
2594Jones141.2
4633Johnson484
154Johnson635.2
2974Johnson20.2
3473Johnson282.3

 

Expected output

DirectorAverage of Tenure(Mth)
Smith36.25
Jones27.25
Johnson35.25
Total Avg32.91666667
Labels (1)
1 Solution

Accepted Solutions
sunny_talwar

Avg([Tenure(Mth)]) should have worked, but you can try this Avg(Aggr(Avg([Tenure(Mth)]), Director))

View solution in original post

3 Replies
sunny_talwar

Avg([Tenure(Mth)]) should have worked, but you can try this Avg(Aggr(Avg([Tenure(Mth)]), Director))

csh8428
Contributor II
Contributor II
Author

tl;dr:  Avg([Tenure(Mth)]) was correct. A joined data-set caused the issue. Fixed the join and that function worked.

Since you said Avg([Tenure(Mth)]) I went back and looked at the data. What was causing the issue was that it was joined to another data-set using Director; however, the other dataset only had the director's last name whereas the one I was posting about has both last and first name, which explains why the total avg worked, but not the director level.

sunny_talwar

okay that make sense