Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum/Count If = Distinct

Hello,

Could somebody please help with the below dilemma?

1. I would like to count all  Transactions that are NB? I think I got this one.

=Count({$<Transaction={'NB'}>}DISTINCT([Policy Number]))

2. I also need to count NB but down to Scheme level. I think I got this one too!

Count({$<[Scheme]={'1'}>}{$<Transaction={'NB'}>}DISTINCT([Policy Number]))

Count({$<[Scheme]={'2'}>}{$<Transaction={'NB'}>}DISTINCT([Policy Number]))

3. This is when my issues start. I would like to Sum(GrossPremium) if(Transaction='NB') and if the policy number is Distinct?

4. Finally I would like to Sum(GrossPremium) IF( Transaction ='NB' or 'CXL'  and if the policy number is distinct ( but the policy number will always be duplicated when there is a different transaction, what I need to do is remove all the duplicated rows I.E Row number 1,2 and 3 is duplicated so should only be counted/summed once).


Any help will be appreciated.

Thanks

Gary

Current Data

PolicyNumberTransactionSchemeGrossPremium

1

NB1

500.00

1NB1500.00
1MTA1175.00
2NB2800.00
2CXL2-800.00
3NB21100.00
3NB21100.00

1NB1

500.00

javascript:;1MTA2100.00
3CXL2

-1050.00

2CXL2-800

Required Straight Table

Total SalesScheme 1 SalesScheme 2 SalesTotal GWPScheme 1 GWP

Scheme 2  GWP

3122400500

1900

1 Solution

Accepted Solutions
Nicole-Smith

For #3:

=sum(aggr(distinct only({<Transaction={'NB'}>}GrossPremium), PolicyNumber))

For #4:

=sum(aggr(distinct only({<Transaction={'NB', 'CXL'}>}GrossPremium), PolicyNumber))

**EDIT:

For #2, you should write it like this:

Count({$<[Scheme]={'1'}, Transaction={'NB'}>}DISTINCT([Policy Number]))

Count({$<[Scheme]={'2'}, Transaction={'NB'}>}DISTINCT([Policy Number]))

View solution in original post

3 Replies
Nicole-Smith

For #3:

=sum(aggr(distinct only({<Transaction={'NB'}>}GrossPremium), PolicyNumber))

For #4:

=sum(aggr(distinct only({<Transaction={'NB', 'CXL'}>}GrossPremium), PolicyNumber))

**EDIT:

For #2, you should write it like this:

Count({$<[Scheme]={'1'}, Transaction={'NB'}>}DISTINCT([Policy Number]))

Count({$<[Scheme]={'2'}, Transaction={'NB'}>}DISTINCT([Policy Number]))

Not applicable
Author

Please try like below:

1. Total Sales = Count({$<Transaction={'NB'}>}DISTINCT[Policy Number]) 

2. Scheme 1 Sales = Count({$< [Scheme]={'1'} , Transaction={'NB'}>} DISTINCT [Policy Number])

3. Scheme 2 Sales = Count({$<[Scheme]={'2'} , Transaction={'NB'}>} DISTINCT [Policy Number])

4. Total GWP = Sum({$<Transaction={'NB'}>} DISTINCT GrossPremium)

5. Total Scheme1 Sales = Sum({$<[Scheme]={'1'} ,Transaction={'NB'}>} DISTINCT GrossPremium)

6. Total Scheme2 Sales = Sum({$<[Scheme]={'2'} ,Transaction={'NB'}>} DISTINCT GrossPremium)

Not applicable
Author

HI Nicole,

Thank you for taking the time to respond to my post!!

Thanks

Gary