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

AGGR (Nested?) Aim: Count only once across 4 fields

Dear all,

I need to aggregate the following. I tried nested aggr but think I may not have gotten the brackets and commas right.

For 1 layer of aggr, I sourced the following:

Aggr(NODISTINCT If([Type (Rank)] = Min(TOTAL <[Group Name]> [Type (Rank)]), [Group Name]), [Group Name], [Type (Rank)])

What I need is for the same group name, I only want to show the Group Name with

(1) the smallest Type (Rank)

(2) the earliest date 

(3) largest amount for Process

e.g.

Group NameType (Rank)DateProcessAmountOutcome (Aggr Group Name)
A11 Feb 2020Pabc10A
A21 Jan 2020Pdef20 
A21 Jan 2020Pabc30 
B31 Apr 2020Pabc10 
B31 Mar 2020Pabc20B
C11 Mar 2020Pdef10 
C11 Mar 2020Pabc8C
C11 Mar 2020Pabc8C
C11 Apr 20Pdef10 
C21 Feb 20Pabc20 

 

I will do a Distinct on the outcome to obtain the final count.

Many thanks in advance!

6 Replies
sunny_talwar

May be this

Aggr(NODISTINCT If(([Type (Rank)]*1e10)+(Date*1e4)-Sum(Amount) = Min(TOTAL <[Group Name]> Aggr(([Type (Rank)]*1e10)+(Date*1e4)-Sum(Amount), [Group Name], [Type (Rank)], Date, Process)), [Group Name]), [Group Name], [Type (Rank)], Date, Process)
NewbieToQV
Contributor II
Contributor II
Author

Wow, that works for the case that I wrote. I tested on the dataset that I have and noticed that I missed out on a scenario.

Thus, the criteria is

(1) the smallest Type (Rank)

(2) the earliest date 

(3) largest amount for Process

(4) If amount is the same then ID_Num by ascending order

 

p NameID_NumType (Rank)DateProcessAmountOutcome (Aggr Group Name)
AID111 Feb 2020Pabc10A
AID221 Jan 2020Pdef20 
AID321 Jan 2020Pabc30 
BID431 Apr 2020Pabc10 
BID531 Mar 2020Pabc20B
CID611 Mar 2020Pdef10 
CID711 Mar 2020Pabc8C
CID811 Mar 2020Pabc8C
CID911 Apr 20Pdef10 
CID1021 Feb 20Pabc20 
DID1111 Mar 2020Pdef16 D
DID1211 Mar 2020Pabc8 
DID1311 Mar 2020Pabc8 
DID1411 Apr 20Pdef10 
DID1521 Feb 20Pabc20 

 

Grateful for your help again.

 

NewbieToQV
Contributor II
Contributor II
Author

Tried to play around with the formulas but still  stuck.... tried to add a rank formula
-aggr(rank(-sum(Amount),0,1),ID_Num) to try to derive the minimum but did not work. What am I missing on?

sunny_talwar

@NewbieToQV If we need to decide first by Amount, why is ID7 and ID8 C here? Shouldn't it be ID6?

image.png

So, I changed ID6 from 10 to 4... but then if we have to choose by Rank of ID_Num, we will have C next to only one ID_Num and I am guessing it would be ID7?

Try this

 

Aggr(NODISTINCT
	If(([Type (Rank)]*1e10)+(Date*1e4)-Sum(Amount)-(Rank(ID_Num)/1E4) = Min(TOTAL <[Group Name]> Aggr(([Type (Rank)]*1e10)+(Date*1e4)-Sum(Amount)-(Rank(ID_Num)/1E4), [Group Name], [Type (Rank)], Date, Process, ID_Num)), [Group Name])
, [Group Name], [Type (Rank)], Date, Process, ID_Num)

 

NewbieToQV
Contributor II
Contributor II
Author

Hi @sunny_talwar , thanks for responding.

On the question of Group C that why ID7 and ID8 is tagged is because I need to count (and mark) to 1 of the IDs and ID7 takes precedence because it is part of the largest category of amounts in process (after rank and date).

"Pabc (ID7 and ID8 )= 16" >  "Pdef (ID6) = 10"

I have attached the qvw for testing as well.

Brett_Bleess
Former Employee
Former Employee

About the only things I have are some Design Blog posts that may be of some help:

https://community.qlik.com/t5/Qlik-Design-Blog/The-nodistinct-qualifier-and-the-Aggr-function/ba-p/1...

https://community.qlik.com/t5/Qlik-Design-Blog/Pitfalls-of-the-Aggr-function/ba-p/1463275

Hopefully they may be of some use.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.