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

Distinct Count and Aggregation


I have the following data set

DealQuarterAmount
Deal 100Q120
Deal 100Q2200
Deal 100Q350000
Deal 100Q4-5000
Deal 101Q326000
Deal 102Q247000
Deal 102Q3500
Deal 103Q47800

I want to display it as follows

DealQ1Q2Q3Q4
Deal 10045220
Deal 10126000
Deal 10247500
Deal 1037800
Deal Count0121

Basically, I want to count deal just once even though it books across multiple quarters and aggregate the amount in the quarter that has the biggest chunk of the booking.

Could you please help?

Thanks,

CD

6 Replies
Anonymous
Not applicable

not clear logic in your expecting result, why Deal 100 has no data for Q1?

chiranjivdas
Contributor III
Contributor III
Author

Because thats how i want it to be.... a deal should appear only once... in the quarter that has the biggest dollar amount... deal 100 has the biggest dollar amount of 50000 in Q3... so it should show up in Q3 as aggregate: 20 + 200 + 50000 - 5000 = 45220.

Not applicable

Here is the solution.

The key to the solution is that for each Deal, identify a Quarter that has received highest Amount.

This expression in Pivot table does the horse work.

if(min(Aggr(rank(Amount),Deal,Quarter))=1, Aggr(Sum(Total <Deal> Amount),Deal,Quarter))

The first part of the expression ranks highest amount. Each Quarter in the Deal will receive a rank which is than checked in 'if' condition whether it is minimum (=1). If the check returns true, it means we are now able to point towards correct Quarter (that holds highest amount) in the Deal.

So then we decide to calculate the Total amount.

In the chart properties/Presentation tab, it is required to uncheck 'Suppress Zero values' so that Q1 column is shown as well.

Unfortunately, I couldn't figure out how to get Deal count at the bottom of Pivot table. (though it can be done in straight table, you would have to sacrifice the cross-table design which is not possible in straight table)

See the attached application.

Warm Regards,

Kalpesh Jain

maxgro
MVP
MVP

=

  if(count(TOTAL <Deal> Amount)=1, sum(Amount),

  if(max(total <Deal> aggr(sum(Amount),Deal,Quarter))=sum(Amount), sum(TOTAL <Deal> Amount) ))

1.png

chiranjivdas
Contributor III
Contributor III
Author

Thanks... both solutions work. But now as I looked into the data set more, I realized I need to 'cleanse' the data at the time of the load. So if a deal has dollar amounts spread over multiple quarters, I want to include a load script that will identify the first quarter that it ever booked in and aggregate the amount in that quarter. For example

Deal 100

Q1: 20

Q2: 200

Q3: 50000

Q4: -5000

I want the script load to pick up 45220 in Q1. Is there a conditional script that I can insert in the load statement to achieve this?

Not applicable

Just append this to the existing load statement

Left Join(Deals)

Load

Deal, MinString(Quarter) as [Quarter],

sum(Amount) as [Total Amount]

Resident Deals

Group by Deal;

Best Regards,

Kalpesh Jain