Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikwiz123
Creator III
Creator III

Show highest and lowest Products based on %

I need to show Highest Product name and lowest product name with respective % values in a Text Box.

I am using the expression below but for some reason, it gives me a blank value.

Highest:

=FirstSortedValue([Product], -Aggr((Count(Distinct {$<[Group]={'Elite'}>} ID)/
Count(Distinct(ID))), [Product ]))

Lowest:

=FirstSortedValue([Product], Aggr((Count(Distinct {$<[Group]={'Elite'}>} ID)/
Count(Distinct(ID))), [Product ]))

Not sure what is wrong with these expressions. Also, if I want to show these High and low Products only if they satisfy a condition (Sum(Items)>100), how do I include this condition in the expression?

Labels (3)
1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

for Part 1 of your query as @KGalloway  suggested, replace count(Distinct (ID) )  with Count(Distinct Total ID )

 

Also, if I want to show these High and low Products only if they satisfy a condition (Sum(Items)>100)

for part 2, add set analysis to FirstSortedValue()  , highlighted

=FirstSortedValue({<[Product]={"=sum(Items)>100"}>}[Product], -Aggr(Count(Distinct {$<[Group]={'Elite'}>} ID)/Count(Distinct Total ID)  , [Product ])  )

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

4 Replies
KGalloway
Creator II
Creator II

Would something like the following work?

KGalloway_0-1675721757052.png

 

Formula for highest product: FirstSortedValue([Product], -Aggr((Count(Distinct {$<[Group]={'Elite'}>} ID)/Count(total ID)), [Product]))

Formula for lowest product: FirstSortedValue([Product], Aggr((Count(Distinct {$<[Group]={'Elite'}>} ID)/Count(total ID)), [Product]))

 

If not, could you provide some sample data and more details on the type of grouping you want to do to find the highest and lowest product?

vinieme12
Champion III
Champion III

for Part 1 of your query as @KGalloway  suggested, replace count(Distinct (ID) )  with Count(Distinct Total ID )

 

Also, if I want to show these High and low Products only if they satisfy a condition (Sum(Items)>100)

for part 2, add set analysis to FirstSortedValue()  , highlighted

=FirstSortedValue({<[Product]={"=sum(Items)>100"}>}[Product], -Aggr(Count(Distinct {$<[Group]={'Elite'}>} ID)/Count(Distinct Total ID)  , [Product ])  )

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
qlikwiz123
Creator III
Creator III
Author

Thank you @vinieme12 

=FirstSortedValue({<[Product]={"=sum(Items)>100"}>}[Product], -Aggr(Count(Distinct {$<[Group]={'Elite'}>} ID)/Count(Distinct Total ID)  , [Product ])  )

What happens if I have more than one Product value which satisfies the above condition?

For example, if Product A and B both have Sum(Items)>100 and have the same Output of 50? Looks like it is picking up the first value that satisfies Sum(Items)>100. In this case A has Sum(Items) as 250 and B has Sum(Items) as 1000, it is showing 'A'.

How do I show B instead of A, since it has more Sum(Items)?

vinieme12
Champion III
Champion III

use a sorted aggr()

 

refer the example here

=Aggr(
    <Expression> ,
    (Product,(=Sum({1} Items ),Desc))
    )

https://community.qlik.com/t5/Design/Recipe-for-a-Pareto-Analysis-Revisited/ba-p/1473684

https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470312

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.