<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic For each dim1 (region), concat the top *n* dim2 values (product), based on measure (SUM(amount)) in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/For-each-dim1-region-concat-the-top-n-dim2-values-product-based/m-p/2047081#M1222893</link>
    <description>&lt;P&gt;Please note I am using &lt;SPAN&gt;qliksenseserver:14.5.22&lt;/SPAN&gt;&lt;BR /&gt;Let me know&amp;nbsp;&lt;BR /&gt;I have data like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl68" style="height: 15.0pt; width: 48pt;"&gt;region&lt;/TD&gt;
&lt;TD width="64" class="xl69" style="width: 48pt;"&gt;product&lt;/TD&gt;
&lt;TD width="64" class="xl70" style="width: 48pt;"&gt;amount&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;South&lt;/TD&gt;
&lt;TD class="xl72"&gt;Item&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl74" style="height: 15.0pt;"&gt;South&lt;/TD&gt;
&lt;TD class="xl75"&gt;Toy&lt;/TD&gt;
&lt;TD align="right" class="xl76"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;South&lt;/TD&gt;
&lt;TD class="xl72"&gt;Stuff&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl74" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl75"&gt;Widget&lt;/TD&gt;
&lt;TD align="right" class="xl76"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl72"&gt;Widget&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl74" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl75"&gt;Toy&lt;/TD&gt;
&lt;TD align="right" class="xl76"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl72"&gt;Stuff&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt;"&gt;East&lt;/TD&gt;
&lt;TD class="xl66"&gt;Stuff&lt;/TD&gt;
&lt;TD align="right" class="xl67"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please notice that a given region might have &lt;STRONG&gt;more than one row&lt;/STRONG&gt; for a given product&lt;/P&gt;
&lt;P&gt;(for example there are two rows for region=North, product=Widget)&lt;/P&gt;
&lt;P&gt;So I think I need to do AGGR, and I'm not sure I can use FIRSTSORTEDVALUE&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;How can I make a &lt;STRONG&gt;straight table&lt;/STRONG&gt;&amp;nbsp;like below...&lt;/P&gt;
&lt;P&gt;(one row per region;&amp;nbsp;shows the product and SUM(AMOUNT) for the product with the highest SUM(amount) (in that region))&lt;/P&gt;
&lt;TABLE width="184"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;region&lt;/TD&gt;
&lt;TD width="120"&gt;top-selling-product&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;South&lt;/TD&gt;
&lt;TD&gt;Item(5)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;North&lt;/TD&gt;
&lt;TD&gt;Widget(50)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;East&lt;/TD&gt;
&lt;TD&gt;Stuff(1)&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or a &lt;STRONG&gt;straight table&lt;/STRONG&gt; like below...&lt;BR /&gt;(one row per region;&amp;nbsp;shows the product&lt;U&gt;&lt;STRONG&gt;s&lt;/STRONG&gt;&lt;/U&gt; and SUM(AMOUNT) for the &lt;STRONG&gt;top&amp;nbsp;two products&lt;/STRONG&gt;&amp;nbsp;with the highest SUM(amount) (in that region), in&amp;nbsp; descending order of SUM(amount))&lt;/P&gt;
&lt;TABLE width="237"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;region&lt;/TD&gt;
&lt;TD width="173"&gt;top-2-selling-products&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;South&lt;/TD&gt;
&lt;TD&gt;Item(5) Toy(3)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;North&lt;/TD&gt;
&lt;TD&gt;Widget(50) Toy(10)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;East&lt;/TD&gt;
&lt;TD&gt;Stuff(1)&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the best I could come up with, it seems to work, but I feel like I over-engineered it (?)&lt;/P&gt;
&lt;P&gt;Note it uses &lt;A href="https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/RelationalFunctions/rank.htm#:~:text=Rank()%20evaluates%20the%20rows,dimension%20evaluated%20in%20the%20expression." target="_self"&gt;&lt;STRONG&gt;a rank() technique&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;CONCAT(&lt;BR /&gt;    AGGR(IF(rank(SUM(amount))&amp;lt;=2, product &amp;amp; SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        product), &lt;BR /&gt;    ' ',&lt;BR /&gt;    // need the CONCAT sort_weight argument , right?&lt;BR /&gt;    // Arturo says that here: https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470305/highlight/true#M4511&lt;BR /&gt;    AGGR(IF(rank(SUM(amount))&amp;lt;=2, -SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        product)&lt;BR /&gt;)&lt;/PRE&gt;
&lt;P&gt;This shows a Qlik table using the above expression, it produces the results I want:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nate_muir_anderson_0-1678318600328.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/102329i12833E9A276AFE9F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nate_muir_anderson_0-1678318600328.png" alt="nate_muir_anderson_0-1678318600328.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This expression also works, not it uses a &lt;STRONG&gt;&lt;A href="https://community.qlik.com/t5/Design/Recipe-for-a-Pareto-Analysis-Revisited/ba-p/1473684" target="_self"&gt;sortable aggr expressions technique&lt;/A&gt;, &lt;/STRONG&gt;therefore it can use&amp;nbsp;&lt;A href="https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/InterRecordFunctions/rowno.htm#:~:text=RowNo()%20returns%20the%20number,the%20chart's%20straight%20table%20equivalent." target="_self"&gt;&lt;STRONG&gt;rowno()&amp;nbsp;&lt;/STRONG&gt;&lt;/A&gt;instead of&amp;nbsp;&lt;A href="https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/RelationalFunctions/rank.htm#:~:text=Rank()%20evaluates%20the%20rows,dimension%20evaluated%20in%20the%20expression." target="_self"&gt;&lt;STRONG&gt;rank().&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CONCAT(&lt;BR /&gt;    AGGR(IF(rowno()&amp;lt;=2, product &amp;amp; SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        (product, (=SUM(amount),DESC))), &lt;BR /&gt;    ' ',&lt;BR /&gt;    // need the CONCAT sort_weight argument , right?&lt;BR /&gt;    // Arturo says that here: https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470305/highlight/true#M4511&lt;BR /&gt;    AGGR(IF(rowno()&amp;lt;=2, -SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        (product, (=SUM(amount),DESC)))&lt;BR /&gt;)&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;Be careful of the sortable aggr expressions syntax, notice the expression is contained inside parentheses, and uses an equals sign as HIC says "&lt;SPAN&gt;Note the equals sign. This is necessary if you want to sort by expression." Specifically, the sort order must be inside&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;...(product, (=SUM(amount), DESCENDING&lt;FONT color="#33CCCC"&gt;&lt;STRONG&gt;&lt;U&gt;)&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;)...&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Not this:&lt;/P&gt;
&lt;PRE&gt;...(product, (=SUM(amount)&lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;, DESCENDING)...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would've worked too (sort by *negative* SUM(amount)), with implied ASCENDING order:&lt;/P&gt;
&lt;PRE&gt;...(product, (=&lt;FONT color="#33CCCC"&gt;&lt;STRONG&gt;-&lt;/STRONG&gt;&lt;/FONT&gt;SUM(amount))...&lt;/PRE&gt;
&lt;P&gt;Here's the load statement I used&lt;/P&gt;
&lt;PRE&gt;LOAD * INLINE [&lt;BR /&gt;region product amount&lt;BR /&gt;South Item 5&lt;BR /&gt;South Toy 3&lt;BR /&gt;South Stuff 2&lt;BR /&gt;North Widget 30&lt;BR /&gt;North Widget 20&lt;BR /&gt;North Toy 10&lt;BR /&gt;North Stuff 5&lt;BR /&gt;East Stuff 1&lt;BR /&gt;] (DELIMITER IS ' ');&lt;/PRE&gt;
&lt;P&gt;Please let me know if this question is a duplicate question (already asked elsewhere)&lt;/P&gt;
&lt;P&gt;I checked resources like these:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470312" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470312&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://help.qlik.com/en-US/sense/2.2/Subsystems/Hub/Content/ChartFunctions/aggr.htm?_ga=2.207914261.644332174.1678214183-563755672.1660841437" target="_blank" rel="noopener"&gt;https://help.qlik.com/en-US/sense/2.2/Subsystems/Hub/Content/ChartFunctions/aggr.htm?_ga=2.207914261.644332174.1678214183-563755672.1660841437&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://help.qlik.com/en-US/qlikview/May2022/Subsystems/Client/Content/QV_QlikView/ChartFunctions/NestedAggregations/nested-aggregations-aggregation-function.htm" target="_blank" rel="noopener"&gt;https://help.qlik.com/en-US/qlikview/May2022/Subsystems/Client/Content/QV_QlikView/ChartFunctions/NestedAggregations/nested-aggregations-aggregation-function.htm&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/New-to-Qlik-Sense/Get-first-row-number-from-that-return-from-aggr/m-p/1768124#M176527" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/New-to-Qlik-Sense/Get-first-row-number-from-that-return-from-aggr/m-p/1768124#M176527&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/QlikView-App-Dev/Concat-a-field-with-a-sort-on-expression/td-p/279063" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/QlikView-App-Dev/Concat-a-field-with-a-sort-on-expression/td-p/279063&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/Design/Recipe-for-a-Pareto-Analysis-Revisited/ba-p/1473684" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Design/Recipe-for-a-Pareto-Analysis-Revisited/ba-p/1473684&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Thu, 09 Mar 2023 00:20:21 GMT</pubDate>
    <dc:creator>nate_muir_anderson</dc:creator>
    <dc:date>2023-03-09T00:20:21Z</dc:date>
    <item>
      <title>For each dim1 (region), concat the top *n* dim2 values (product), based on measure (SUM(amount))</title>
      <link>https://community.qlik.com/t5/QlikView/For-each-dim1-region-concat-the-top-n-dim2-values-product-based/m-p/2047081#M1222893</link>
      <description>&lt;P&gt;Please note I am using &lt;SPAN&gt;qliksenseserver:14.5.22&lt;/SPAN&gt;&lt;BR /&gt;Let me know&amp;nbsp;&lt;BR /&gt;I have data like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl68" style="height: 15.0pt; width: 48pt;"&gt;region&lt;/TD&gt;
&lt;TD width="64" class="xl69" style="width: 48pt;"&gt;product&lt;/TD&gt;
&lt;TD width="64" class="xl70" style="width: 48pt;"&gt;amount&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;South&lt;/TD&gt;
&lt;TD class="xl72"&gt;Item&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl74" style="height: 15.0pt;"&gt;South&lt;/TD&gt;
&lt;TD class="xl75"&gt;Toy&lt;/TD&gt;
&lt;TD align="right" class="xl76"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;South&lt;/TD&gt;
&lt;TD class="xl72"&gt;Stuff&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl74" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl75"&gt;Widget&lt;/TD&gt;
&lt;TD align="right" class="xl76"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl72"&gt;Widget&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;20&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl74" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl75"&gt;Toy&lt;/TD&gt;
&lt;TD align="right" class="xl76"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;North&lt;/TD&gt;
&lt;TD class="xl72"&gt;Stuff&lt;/TD&gt;
&lt;TD align="right" class="xl73"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl65" style="height: 15.0pt;"&gt;East&lt;/TD&gt;
&lt;TD class="xl66"&gt;Stuff&lt;/TD&gt;
&lt;TD align="right" class="xl67"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please notice that a given region might have &lt;STRONG&gt;more than one row&lt;/STRONG&gt; for a given product&lt;/P&gt;
&lt;P&gt;(for example there are two rows for region=North, product=Widget)&lt;/P&gt;
&lt;P&gt;So I think I need to do AGGR, and I'm not sure I can use FIRSTSORTEDVALUE&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;How can I make a &lt;STRONG&gt;straight table&lt;/STRONG&gt;&amp;nbsp;like below...&lt;/P&gt;
&lt;P&gt;(one row per region;&amp;nbsp;shows the product and SUM(AMOUNT) for the product with the highest SUM(amount) (in that region))&lt;/P&gt;
&lt;TABLE width="184"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;region&lt;/TD&gt;
&lt;TD width="120"&gt;top-selling-product&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;South&lt;/TD&gt;
&lt;TD&gt;Item(5)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;North&lt;/TD&gt;
&lt;TD&gt;Widget(50)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;East&lt;/TD&gt;
&lt;TD&gt;Stuff(1)&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or a &lt;STRONG&gt;straight table&lt;/STRONG&gt; like below...&lt;BR /&gt;(one row per region;&amp;nbsp;shows the product&lt;U&gt;&lt;STRONG&gt;s&lt;/STRONG&gt;&lt;/U&gt; and SUM(AMOUNT) for the &lt;STRONG&gt;top&amp;nbsp;two products&lt;/STRONG&gt;&amp;nbsp;with the highest SUM(amount) (in that region), in&amp;nbsp; descending order of SUM(amount))&lt;/P&gt;
&lt;TABLE width="237"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;region&lt;/TD&gt;
&lt;TD width="173"&gt;top-2-selling-products&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;South&lt;/TD&gt;
&lt;TD&gt;Item(5) Toy(3)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;North&lt;/TD&gt;
&lt;TD&gt;Widget(50) Toy(10)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;East&lt;/TD&gt;
&lt;TD&gt;Stuff(1)&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the best I could come up with, it seems to work, but I feel like I over-engineered it (?)&lt;/P&gt;
&lt;P&gt;Note it uses &lt;A href="https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/RelationalFunctions/rank.htm#:~:text=Rank()%20evaluates%20the%20rows,dimension%20evaluated%20in%20the%20expression." target="_self"&gt;&lt;STRONG&gt;a rank() technique&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;CONCAT(&lt;BR /&gt;    AGGR(IF(rank(SUM(amount))&amp;lt;=2, product &amp;amp; SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        product), &lt;BR /&gt;    ' ',&lt;BR /&gt;    // need the CONCAT sort_weight argument , right?&lt;BR /&gt;    // Arturo says that here: https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470305/highlight/true#M4511&lt;BR /&gt;    AGGR(IF(rank(SUM(amount))&amp;lt;=2, -SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        product)&lt;BR /&gt;)&lt;/PRE&gt;
&lt;P&gt;This shows a Qlik table using the above expression, it produces the results I want:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nate_muir_anderson_0-1678318600328.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/102329i12833E9A276AFE9F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nate_muir_anderson_0-1678318600328.png" alt="nate_muir_anderson_0-1678318600328.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This expression also works, not it uses a &lt;STRONG&gt;&lt;A href="https://community.qlik.com/t5/Design/Recipe-for-a-Pareto-Analysis-Revisited/ba-p/1473684" target="_self"&gt;sortable aggr expressions technique&lt;/A&gt;, &lt;/STRONG&gt;therefore it can use&amp;nbsp;&lt;A href="https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/InterRecordFunctions/rowno.htm#:~:text=RowNo()%20returns%20the%20number,the%20chart's%20straight%20table%20equivalent." target="_self"&gt;&lt;STRONG&gt;rowno()&amp;nbsp;&lt;/STRONG&gt;&lt;/A&gt;instead of&amp;nbsp;&lt;A href="https://help.qlik.com/en-US/sense/February2023/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/RelationalFunctions/rank.htm#:~:text=Rank()%20evaluates%20the%20rows,dimension%20evaluated%20in%20the%20expression." target="_self"&gt;&lt;STRONG&gt;rank().&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CONCAT(&lt;BR /&gt;    AGGR(IF(rowno()&amp;lt;=2, product &amp;amp; SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        (product, (=SUM(amount),DESC))), &lt;BR /&gt;    ' ',&lt;BR /&gt;    // need the CONCAT sort_weight argument , right?&lt;BR /&gt;    // Arturo says that here: https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470305/highlight/true#M4511&lt;BR /&gt;    AGGR(IF(rowno()&amp;lt;=2, -SUM(amount)), &lt;BR /&gt;        region, // otherwise "grain mismatch" as HIC says https://community.qlik.com/t5/Design/Pitfalls-of-the-Aggr-function/ba-p/1463275&lt;BR /&gt;        (product, (=SUM(amount),DESC)))&lt;BR /&gt;)&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;Be careful of the sortable aggr expressions syntax, notice the expression is contained inside parentheses, and uses an equals sign as HIC says "&lt;SPAN&gt;Note the equals sign. This is necessary if you want to sort by expression." Specifically, the sort order must be inside&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;...(product, (=SUM(amount), DESCENDING&lt;FONT color="#33CCCC"&gt;&lt;STRONG&gt;&lt;U&gt;)&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;)...&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Not this:&lt;/P&gt;
&lt;PRE&gt;...(product, (=SUM(amount)&lt;FONT color="#FF0000"&gt;&lt;U&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;, DESCENDING)...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would've worked too (sort by *negative* SUM(amount)), with implied ASCENDING order:&lt;/P&gt;
&lt;PRE&gt;...(product, (=&lt;FONT color="#33CCCC"&gt;&lt;STRONG&gt;-&lt;/STRONG&gt;&lt;/FONT&gt;SUM(amount))...&lt;/PRE&gt;
&lt;P&gt;Here's the load statement I used&lt;/P&gt;
&lt;PRE&gt;LOAD * INLINE [&lt;BR /&gt;region product amount&lt;BR /&gt;South Item 5&lt;BR /&gt;South Toy 3&lt;BR /&gt;South Stuff 2&lt;BR /&gt;North Widget 30&lt;BR /&gt;North Widget 20&lt;BR /&gt;North Toy 10&lt;BR /&gt;North Stuff 5&lt;BR /&gt;East Stuff 1&lt;BR /&gt;] (DELIMITER IS ' ');&lt;/PRE&gt;
&lt;P&gt;Please let me know if this question is a duplicate question (already asked elsewhere)&lt;/P&gt;
&lt;P&gt;I checked resources like these:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470312" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Design/The-sortable-Aggr-function-is-finally-here/bc-p/1470312&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://help.qlik.com/en-US/sense/2.2/Subsystems/Hub/Content/ChartFunctions/aggr.htm?_ga=2.207914261.644332174.1678214183-563755672.1660841437" target="_blank" rel="noopener"&gt;https://help.qlik.com/en-US/sense/2.2/Subsystems/Hub/Content/ChartFunctions/aggr.htm?_ga=2.207914261.644332174.1678214183-563755672.1660841437&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://help.qlik.com/en-US/qlikview/May2022/Subsystems/Client/Content/QV_QlikView/ChartFunctions/NestedAggregations/nested-aggregations-aggregation-function.htm" target="_blank" rel="noopener"&gt;https://help.qlik.com/en-US/qlikview/May2022/Subsystems/Client/Content/QV_QlikView/ChartFunctions/NestedAggregations/nested-aggregations-aggregation-function.htm&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/New-to-Qlik-Sense/Get-first-row-number-from-that-return-from-aggr/m-p/1768124#M176527" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/New-to-Qlik-Sense/Get-first-row-number-from-that-return-from-aggr/m-p/1768124#M176527&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/QlikView-App-Dev/Concat-a-field-with-a-sort-on-expression/td-p/279063" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/QlikView-App-Dev/Concat-a-field-with-a-sort-on-expression/td-p/279063&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://community.qlik.com/t5/Design/Recipe-for-a-Pareto-Analysis-Revisited/ba-p/1473684" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Design/Recipe-for-a-Pareto-Analysis-Revisited/ba-p/1473684&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 09 Mar 2023 00:20:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/For-each-dim1-region-concat-the-top-n-dim2-values-product-based/m-p/2047081#M1222893</guid>
      <dc:creator>nate_muir_anderson</dc:creator>
      <dc:date>2023-03-09T00:20:21Z</dc:date>
    </item>
  </channel>
</rss>

