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

Distinct sums

  Here is a simple example of the type of data I am working with. I want to pivot it so that only $ for distinct opportunity names are added together. In other words, I want the sum of $ won to be 21k instead of 27k because I want the $ associated with hospital x to be counted only once. I can't use sum distinct because  it will treat UMASS and Hospital X as the same item and will only sum everything to 15k. Please help.  

Marketing campaignLEAD NameOpportunity Name$ won
AJohnUMASS Hospital6000
AjonathanHospital X6000
AcindyHospital X6000
ABobHarvard Hospital8000
AKateClinic A1000
7 Replies
sergio0592
Specialist III
Specialist III

Hi,

You can achieve 21k with as expression:

if (not IsNull(aggr(RowNo(), [Opportunity Name])), sum([$ won]))

Pic2.jpg

Anonymous
Not applicable
Author

Thank you but I noticed that for this work my pivot must have Opportunity name as one of the dimensions. However, I want to be able to simply sum by campaign without showing individual opportunities. any way to achieve that? Thanks again

Anonymous
Not applicable
Author

Sorry I meant to say that for this work my pivot has to have lead name as one of the dimensions. However, I want to be able to simply sum by campaign name without showing individual opportunities or leads. any way to achieve that? Thanks again

vishsaggi
Champion III
Champion III

What is your expected output?

Anonymous
Not applicable
Author

In this case,

   

Marketing campaignTotal $ Won
A21000
vishsaggi
Champion III
Champion III

Try this in your expr:

= Sum(Aggr(IF(Count([Opportunity Name])>1, Sum(DISTINCT [$ won]), Sum([$ won])), [Marketing campaign], [Opportunity Name]))

OR

= Sum(Aggr(IF(Count([Opportunity Name])>1, Only([$ won]), [$ won]), [Marketing campaign], [Opportunity Name]))

qlikviewwizard
Master II
Master II

Hi You can use this.

=if(count([Opportunity Name])>1,sum(Aggr([$ Won],[Opportunity Name])),sum([$ Won]))

Capture.PNG