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: 
that_anonymous_guy
Contributor III
Contributor III

Calculate sum based on a column

B C
01 7%
01 7%
01 7%
02 5%
02 5%
02 5%
03 7%
03 7%
03 7%

 

I want to calculate sum of B but I want to take only one instance of B for every A. For eg: it should be (7+5+7) ie 7 for A-01 5 for A-02 7 for A-03

Labels (4)
2 Replies
E_Røse
Creator II
Creator II

You could try something like

 

=sum(aggr(avg(C), B))

 

Alternatively, you can replace avg with min, max or only, depending on what you want to happen if there are multiple values in column c for a given value in column b? Below I altered your example slightly, so that you can see what the output would be if for B=01, if you have two different values in column C

Elin_Rse_1-1677059731275.png

Please like and mark my answer as a solution, if it resolved your issue.

ogster1974
Partner - Master II
Partner - Master II

Something like this.

NoConcatenate
Tmp:
Load * Inline [
Row, B, C
1, 01, 7%
2, 01, 7%
3, 01, 7%
4, 02, 5%
5, 02, 5%
6, 02, 5%
7, 03, 7%
8, 03, 7%
9, 03, 7%
]
;

NoConcatenate
Final:
Load
Row,
If(B=Peek(B),Peek('A')+1,1) AS A,
B,
C
Resident Tmp
;

Drop Table Tmp;

ogster1974_0-1677058949409.png