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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Mode and Prices

Hello!

I have a little table like this:

PeriodCitySkuBrandPriceSales
201301ASku1Alpha1.5100
201301ASku2Alpha1.5150
201301ASku3Beta1.6120
201301BSku1Alpha1.4130
201301BSku2Alpha1.4120
201301BSku3Beta1.3100
201301CSku1Alpha1.5120
201301CSku2Alpha1.4110
201301CSku3Beta1.3130
201301CSku4Gamma1.3130
201301CSku5Gamma1.3150

I just want to build a Pivot Table that calculates the sum of the sales by city where the price equals the modal price (also by city).

I can't seem to find out how to solve this problem.

Any help would be really appreciated!

PS: I'm attaching a qvw with the table and what I've done so far...

Labels (1)
1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

Sorry, I forgot a "nodistinct"

Sum(If(Price=Aggr(nodistinct Mode(Price),Period,City), Sales))

HIC

View solution in original post

10 Replies
hic
Former Employee
Former Employee

Sum(If(Price=Aggr(Mode(Price),Period,City), Sales))

HIC

sujeetsingh
Master III
Master III

Please explain more deep

matthias_v
Partner - Contributor III
Partner - Contributor III

Hi Ruben,

I adjusted your example to fit your needs (see attachment). I placed the logic in the script as to gain performance towards your end-users.

Not applicable
Author

Thanks for your answer Henric Cronström !

I used your expression but, sadly, I'm still not getting the correct numbers:

The correct numbers should be the ones on the textboxes to the right.

Am I doing something wrong?

hic
Former Employee
Former Employee

Set analysis is not the answer here, since Ruben wants to make a comparison on every row of the pivot table. Set analysis will use a common "selection" for all rows.

So, instead I use the Aggr() function, which in this case calculates the most common value (Mode(Price)) for each combination of Period and City, and then this value is used to select the relevant transactions.

HIC

Not applicable
Author

Hi Matthias,

Thanks for your answer!

I tried you approach and it works, I get the numbers.

But can this be done in a more "dynamic" way?

I just used "period" and "city" as dimensions, but if I add another (let's say "brand") I would have to reconfigure the LEFT JOIN in your script

Thanks in advance!

hic
Former Employee
Former Employee

Sorry, I forgot a "nodistinct"

Sum(If(Price=Aggr(nodistinct Mode(Price),Period,City), Sales))

HIC

matthias_v
Partner - Contributor III
Partner - Contributor III

Hey Ruben,

In that case Henric has the answer you seek.

Not applicable
Author

Excellent Henric!!!!

It works!!!