Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Saurabh07
Contributor III
Contributor III

Expression to get Main field for each attribute

Hi,

I have mentioned structure of data source table;

Company_NameIDCountryProductValue
Company A1234JapanBL_175
Company A1234JapanBL_2125
Company A1234JapanBL_3100
Company B5678IndiaBL_450
Company B5678IndiaBL_325

 

In my  Qlik report I am trying to develop an expression using set analysis to get Main product, ie. Product with highest share of Value for each Company.

Company_NameIDSegmentTotal ValueMain Product
Company A1234Segment 1300BL_2 (42%)
Company B1234Segment 275BL_4 (67%)

To acheive this, I am using the mentioned set expression ;

=Value / aggr(sum(Value),Company_Name)

But is giving the share of all the products. How do I get only the Main Product to be displayed? I believe I need to use Rank function, but cant figure out how?

Can anyone help me out with this please?

1 Solution

Accepted Solutions
Taoufiq_Zarra

@Saurabh07  are you looking for :

Input data :

Capture.PNG

Dimenstion: Company name and ID

Expression :

for Total Value :

=sum(total <Company_Name> Value)

 

and Product main:

=FirstSortedValue(Product,-aggr(sum(Value),Company_Name,Product))

 

value main product:

=Num(Max(aggr(Max(Value),Company_Name,Product))/sum(total <Company_Name> Value),'# ##0%')

 

so you can combine values as :

=FirstSortedValue(Product,-aggr(sum(Value),Company_Name,Product))&' ('&Num(Max(aggr(Max(Value),Company_Name,Product))/sum(total <Company_Name> Value),'# ##0%')&')' 

 

output:

Capture.PNG

 

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

4 Replies
Taoufiq_Zarra

@Saurabh07  are you looking for :

Input data :

Capture.PNG

Dimenstion: Company name and ID

Expression :

for Total Value :

=sum(total <Company_Name> Value)

 

and Product main:

=FirstSortedValue(Product,-aggr(sum(Value),Company_Name,Product))

 

value main product:

=Num(Max(aggr(Max(Value),Company_Name,Product))/sum(total <Company_Name> Value),'# ##0%')

 

so you can combine values as :

=FirstSortedValue(Product,-aggr(sum(Value),Company_Name,Product))&' ('&Num(Max(aggr(Max(Value),Company_Name,Product))/sum(total <Company_Name> Value),'# ##0%')&')' 

 

output:

Capture.PNG

 

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Saurabh07
Contributor III
Contributor III
Author

@Taoufiq_Zarra This worked like magic. Awesome! Thanks a ton! So was the trick with the FirstSortedValue function instead of Rank? and why do we put - sign before aggr? It would be great help if you help me understand this function!!!!

Thank you again!

Taoufiq_Zarra

@Saurabh07  FirstSortedValue() returns the value from the expression taking into account rank (- for the max )

you can read this article

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Saurabh07
Contributor III
Contributor III
Author

@Taoufiq_Zarra  Great, thanks!!