<?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 Re: A Problem on Data Grouping in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/A-Problem-on-Data-Grouping/m-p/2097326#M1224276</link>
    <description>&lt;P&gt;&lt;SPAN&gt;To apply the A/B/C stock logic on a per week basis, we need to calculate the category thresholds dynamically based on the sales for each week. Here is one way to do it in DAX:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Stock Category = 
VAR TotalSales = 
    SUMX(SUMMARIZE('Sales', 'Sales'[ArticleCode], 'Sales'[Week], "Sales Total", SUM('Sales'[Sales])), [Sales Total])
VAR CumulativeSales =
    CALCULATE(
        SUM('Sales'[Sales]),
        FILTER(ALL('Sales'), 'Sales'[Week] &amp;lt;= MAX('Sales'[Week])),
        GROUPBY('Sales'[ArticleCode], 'Sales'[Week])
    )
RETURN
    SWITCH(
        TRUE(),
        CumulativeSales &amp;lt;= 0.6 * TotalSales, "A Stocks",
        CumulativeSales &amp;lt;= 0.9 * TotalSales, "B Stocks",
        "C Stocks"
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See here: &lt;A href="https://www.myenvoyair.net/" target="_self"&gt;myenvoyair login&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This calculates the total sales for each week, then uses a cumulative sum to calculate the running percentage of sales for each article up to that week. We can then categorize based on whether the cumulative percentage is less than 60% or 90% of the total for that week.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2023 12:03:36 GMT</pubDate>
    <dc:creator>Phoebe5776</dc:creator>
    <dc:date>2023-07-27T12:03:36Z</dc:date>
    <item>
      <title>A Problem on Data Grouping</title>
      <link>https://community.qlik.com/t5/QlikView/A-Problem-on-Data-Grouping/m-p/2095243#M1224236</link>
      <description>&lt;P&gt;Hi Buddy,&lt;/P&gt;
&lt;P&gt;Each week we sold thousands of&amp;nbsp; articles&amp;nbsp; and would like to group these articles according to three groups:&lt;BR /&gt;A STOCKS are top articles accounted for 60% of total sales,&amp;nbsp; B STOCKS accounted for the next 30% of total sales, and the left 10% are C STOCKS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is the dimension of grouping is only applicable for the total number&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the requirement is to apply this logic to each week,&amp;nbsp; how to remedy the dimension logic as follow:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="simsun,hei"&gt;=aggr(&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="simsun,hei"&gt;if(rangesum(above(sum({&amp;lt;Year={"$(=$(vmaxyear))"},Week={"&amp;lt;=$(=Week(today()-7))"}&amp;gt;} sales)/sum(total {&amp;lt;Year={"$(=$(vmaxyear))"},Week={"&amp;lt;=$(=Week(today()-7))"}&amp;gt;} sales),1,RowNo()))&amp;lt;0.6,'A STOCKS',&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="simsun,hei"&gt;if(rangesum(above(sum({&amp;lt;Year={"$(=$(vmaxyear))"},Week={"&amp;lt;=$(=Week(today()-7))"}&amp;gt;} sales)/sum(total {&amp;lt;Year={"$(=$(vmaxyear))"},Week={"&amp;lt;=$(=Week(today()-7))"}&amp;gt;} sales),1,RowNo()))&amp;lt;0.9,'B STOCKS',&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="simsun,hei"&gt;'C STOCKS')),(ArticleCode,(=SUM({&amp;lt;Year={"$(=$(vmaxyear))"},Week={"&amp;lt;=$(=Week(today()-7))"}&amp;gt;} sales),Desc)))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached is the&amp;nbsp; layout result for reference, which is not correct&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking forward to your answer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regard!&lt;/P&gt;
&lt;P&gt;Lynn Li&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 11:01:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/A-Problem-on-Data-Grouping/m-p/2095243#M1224236</guid>
      <dc:creator>LynnLI</dc:creator>
      <dc:date>2023-07-19T11:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: A Problem on Data Grouping</title>
      <link>https://community.qlik.com/t5/QlikView/A-Problem-on-Data-Grouping/m-p/2097326#M1224276</link>
      <description>&lt;P&gt;&lt;SPAN&gt;To apply the A/B/C stock logic on a per week basis, we need to calculate the category thresholds dynamically based on the sales for each week. Here is one way to do it in DAX:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Stock Category = 
VAR TotalSales = 
    SUMX(SUMMARIZE('Sales', 'Sales'[ArticleCode], 'Sales'[Week], "Sales Total", SUM('Sales'[Sales])), [Sales Total])
VAR CumulativeSales =
    CALCULATE(
        SUM('Sales'[Sales]),
        FILTER(ALL('Sales'), 'Sales'[Week] &amp;lt;= MAX('Sales'[Week])),
        GROUPBY('Sales'[ArticleCode], 'Sales'[Week])
    )
RETURN
    SWITCH(
        TRUE(),
        CumulativeSales &amp;lt;= 0.6 * TotalSales, "A Stocks",
        CumulativeSales &amp;lt;= 0.9 * TotalSales, "B Stocks",
        "C Stocks"
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See here: &lt;A href="https://www.myenvoyair.net/" target="_self"&gt;myenvoyair login&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This calculates the total sales for each week, then uses a cumulative sum to calculate the running percentage of sales for each article up to that week. We can then categorize based on whether the cumulative percentage is less than 60% or 90% of the total for that week.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 12:03:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/A-Problem-on-Data-Grouping/m-p/2097326#M1224276</guid>
      <dc:creator>Phoebe5776</dc:creator>
      <dc:date>2023-07-27T12:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: A Problem on Data Grouping</title>
      <link>https://community.qlik.com/t5/QlikView/A-Problem-on-Data-Grouping/m-p/2097646#M1224278</link>
      <description>&lt;P&gt;Finally,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We combined articlecode &amp;amp; Week together to aggregate and came to the correct result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the dimension in case any user in need:&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;
&lt;P&gt;=aggr(IF(SUM({&amp;lt;Year={"$(=$(vmaxyear))"}&amp;gt;}sales)&amp;gt;0,&lt;/P&gt;
&lt;P&gt;if(rangesum(above(sum({&amp;lt;Year={"$(=$(vmaxyear))"}&amp;gt;}sales)/sum(total&amp;lt;Week&amp;gt; {&amp;lt;Year={"$(=$(vmaxyear))"}&amp;gt;}sales),1,RowNo()))&amp;lt;0.6,'A STOCKS',&lt;/P&gt;
&lt;P&gt;if(rangesum(above(sum({&amp;lt;Year={"$(=$(vmaxyear))"}&amp;gt;}sales)/sum(total&amp;lt;Week&amp;gt; {&amp;lt;Year={"$(=$(vmaxyear))"}&amp;gt;}sales),1,RowNo()))&amp;lt;0.9,'B STOCKS',&lt;/P&gt;
&lt;P&gt;'C STOCKS')),),Week,(ArticleCode_WeekName,(=SUM({&amp;lt;Year={"$(=$(vmaxyear))"}&amp;gt;}sales),Desc)))&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 27 Jul 2023 02:50:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/A-Problem-on-Data-Grouping/m-p/2097646#M1224278</guid>
      <dc:creator>LynnLI</dc:creator>
      <dc:date>2023-07-27T02:50:47Z</dc:date>
    </item>
  </channel>
</rss>

