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

Count based on multiple columns

Hi,

I need to count certain students based on the their category and the count should be posted on their 'Master's ' row.  can someone please look  in below..  - last column is the expected answer. ...

IDItemStudentCategoryMaster_RefSub Count 
2110Master-1Master 6
2220ST-2SUB10 
2330ST-3SUB10 
2440ST-4SUB10 
2550ST-5SUB10 
2660ST-5SUB10 
2770ST-5SUB10 
2880Master-2Master 2
2990ST-7SUB80 
30100ST-8SUB80 
Labels (2)
1 Solution

Accepted Solutions
sunny_talwar

Try this

If(Category = 'Master', Aggr(NODISTINCT Count(DISTINCT ID), Master_Ref)))

View solution in original post

10 Replies
sunny_talwar

Is this needed in the script or front end?

jt422605
Contributor III
Contributor III
Author

Hi Sunny - Its on front end - as selection would impact the counts as well 

sunny_talwar

If there another field which is common between the rows that needs to be counted and the row where they need to be displayed? For Example Is Master_Ref also available on Master row?

jt422605
Contributor III
Contributor III
Author

Hi Sunny - 

Basically we need to count  on below conditions ... 

Category = 'SUB'  and Item =  Master_Ref  

then count all  item where Category = 'SUB'  and put the total on row Category = 'Master'

sunny_talwar

I understand that bit... but do you have a field which has the same value for SUB and MASTER rows?

jt422605
Contributor III
Contributor III
Author

Spoiler
 

no sunny - 

jt422605
Contributor III
Contributor III
Author

hi Sunny - I am thinking to create new field  OR amend master_ref   for sake of calculations...  if this helps - have a look .

DItemStudentCategoryMaster_RefSub Count 
2110Master-1Master106
2220ST-2SUB10 
2330ST-3SUB10 
2440ST-4SUB10 
2550ST-5SUB10 
2660ST-5SUB10 
2770ST-5SUB10 
2880Master-2Master802
2990ST-7SUB80 
30100ST-8SUB80 
sunny_talwar

Try this

If(Category = 'Master', Aggr(NODISTINCT Count(DISTINCT ID), Master_Ref)))
jt422605
Contributor III
Contributor III
Author

Thanks genius  🙂 

I will further try to accommodate it Set Analysis.