Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Tee_dubs
Contributor III
Contributor III

Sum of Distinct values of another field

I have a table

TASKNUMBERACCESSACCESSKEYMH
A   
A824A-8240.025
B824B-8240.025
B195B-1950.02
C195C-1950.02

 

I want to sum the values of MH only once for the Distinct values of 'ACCESS' 

This is what I have so far.

sum(Aggr(Count(distinct ACCESS),ACC_MH)),ACC_MH) 

It driving me a bit crazy. The solution to this will come in very handy for my whole app. 

I don't think I can avoid AGGR here, however, Performance is becoming a concern so a Set Analysis solution is preferred.

Labels (2)
4 Replies
sunny_talwar

Set analysis won't work here... but you can try this

Sum(Aggr(Sum(MH), ACCESSKEY))

Alternatively, you can take ACCESS and MH from your table and add it to another table in the backend so that only the distinct combination of ACCESS and MH exists and will join to your main table on ACCESS... if you do that, you will be able to just do Sum(MH)....

Tee_dubs
Contributor III
Contributor III
Author

That will give me the Sum(MH) in the example above the answer will be 0.09 the sum of all MH aggregated by the distinct key Accesskey.
What I want is 0.045 or the sum of the 2 distinct accesses 824 and 195.
Perhaps the best idea would be to remove the MH column from the source and create a new Table with only the ACCESS and MH...
sunny_talwar

My so very bad... I think I am ready for the weekend... try this

Sum(Aggr(Sum(DISTINCT MH), ACCESSKEY))
Tee_dubs
Contributor III
Contributor III
Author

Don't feel bad. You've been a great help with my last few posts. Have an awesome weekend!! I'll give that a try but i think changing the back end as suggested is the way to go. 😉