<?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 Getting sum of goods for the first date of each month in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Getting-sum-of-goods-for-the-first-date-of-each-month/m-p/1894071#M1217426</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;Supposing, I have data as following:&lt;/P&gt;
&lt;P&gt;Test:&lt;BR /&gt;LOAD Date(%Date)as %Date, %Month, %GoodId, %Count&lt;BR /&gt;INLINE [&lt;BR /&gt;%Date, %Month, %GoodId, %Count&lt;BR /&gt;30.01.2022, January, 1, 1&lt;BR /&gt;30.01.2022, January, 2, 2&lt;BR /&gt;31.01.2022, January, 1, 4&lt;BR /&gt;31.01.2022, January, 2, 8&lt;BR /&gt;01.02.2022, February, 1, 16&lt;BR /&gt;01.02.2022, February, 2, 32&lt;BR /&gt;02.02.2022, February, 1, 64&lt;BR /&gt;02.02.2022, February, 2, 128&lt;BR /&gt;]&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to find the total count of goods (for both good 1 and 2) for a minimum date for each month. I have tried two ways to get the expected result:&lt;/P&gt;
&lt;P&gt;1)&lt;STRONG&gt; =SUM({&amp;lt;%Date={"$(=Min(%Date))"}&amp;gt;} %Count)&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;-&amp;nbsp;this results in count for the minimum date of all the data, not for an each month&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;&lt;STRONG&gt;=SUM({&amp;lt;%Date={"=Min(%Date)"}&amp;gt;} %Count)&amp;nbsp;&lt;/STRONG&gt;- and this gets total count for each month, in other words filter for min date does not work&lt;/P&gt;
&lt;P&gt;But when I just want to find a minimum date by using&amp;nbsp;&lt;STRONG&gt;=Min(%Date) &lt;/STRONG&gt;, the expression gets an expected minimum date of a month&lt;/P&gt;
&lt;P&gt;Raw data:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chetverikov_0-1645073916269.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/72492iBBD2D0CA24F53A32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="chetverikov_0-1645073916269.png" alt="chetverikov_0-1645073916269.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Results of the expressions ("30.01.2022" is evaluation of "&lt;STRONG&gt;$(=Min(%Date))&lt;/STRONG&gt;"):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chetverikov_1-1645074007466.png" style="width: 645px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/72493iC30725C23DC0C98C/image-dimensions/645x79?v=v2" width="645" height="79" role="button" title="chetverikov_1-1645074007466.png" alt="chetverikov_1-1645074007466.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What I want to get:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;%Month&lt;/TD&gt;
&lt;TD&gt;CountOfMinDate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;February&lt;/TD&gt;
&lt;TD width="50%"&gt;48&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;January&lt;/TD&gt;
&lt;TD width="50%"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help?&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPD: I have restrictions for a solution to my problem:&lt;/P&gt;
&lt;P&gt;1) Period of data can be changed by user&amp;nbsp;arbitrarily&lt;/P&gt;
&lt;P&gt;2) There can be several time dimesions (day, week, month, ...), which are chosen by user&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>Fri, 18 Feb 2022 06:06:51 GMT</pubDate>
    <dc:creator>chetverikov</dc:creator>
    <dc:date>2022-02-18T06:06:51Z</dc:date>
    <item>
      <title>Getting sum of goods for the first date of each month</title>
      <link>https://community.qlik.com/t5/QlikView/Getting-sum-of-goods-for-the-first-date-of-each-month/m-p/1894071#M1217426</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;Supposing, I have data as following:&lt;/P&gt;
&lt;P&gt;Test:&lt;BR /&gt;LOAD Date(%Date)as %Date, %Month, %GoodId, %Count&lt;BR /&gt;INLINE [&lt;BR /&gt;%Date, %Month, %GoodId, %Count&lt;BR /&gt;30.01.2022, January, 1, 1&lt;BR /&gt;30.01.2022, January, 2, 2&lt;BR /&gt;31.01.2022, January, 1, 4&lt;BR /&gt;31.01.2022, January, 2, 8&lt;BR /&gt;01.02.2022, February, 1, 16&lt;BR /&gt;01.02.2022, February, 2, 32&lt;BR /&gt;02.02.2022, February, 1, 64&lt;BR /&gt;02.02.2022, February, 2, 128&lt;BR /&gt;]&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to find the total count of goods (for both good 1 and 2) for a minimum date for each month. I have tried two ways to get the expected result:&lt;/P&gt;
&lt;P&gt;1)&lt;STRONG&gt; =SUM({&amp;lt;%Date={"$(=Min(%Date))"}&amp;gt;} %Count)&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;-&amp;nbsp;this results in count for the minimum date of all the data, not for an each month&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;&lt;STRONG&gt;=SUM({&amp;lt;%Date={"=Min(%Date)"}&amp;gt;} %Count)&amp;nbsp;&lt;/STRONG&gt;- and this gets total count for each month, in other words filter for min date does not work&lt;/P&gt;
&lt;P&gt;But when I just want to find a minimum date by using&amp;nbsp;&lt;STRONG&gt;=Min(%Date) &lt;/STRONG&gt;, the expression gets an expected minimum date of a month&lt;/P&gt;
&lt;P&gt;Raw data:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chetverikov_0-1645073916269.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/72492iBBD2D0CA24F53A32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="chetverikov_0-1645073916269.png" alt="chetverikov_0-1645073916269.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Results of the expressions ("30.01.2022" is evaluation of "&lt;STRONG&gt;$(=Min(%Date))&lt;/STRONG&gt;"):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="chetverikov_1-1645074007466.png" style="width: 645px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/72493iC30725C23DC0C98C/image-dimensions/645x79?v=v2" width="645" height="79" role="button" title="chetverikov_1-1645074007466.png" alt="chetverikov_1-1645074007466.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What I want to get:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;%Month&lt;/TD&gt;
&lt;TD&gt;CountOfMinDate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;February&lt;/TD&gt;
&lt;TD width="50%"&gt;48&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%"&gt;January&lt;/TD&gt;
&lt;TD width="50%"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help?&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPD: I have restrictions for a solution to my problem:&lt;/P&gt;
&lt;P&gt;1) Period of data can be changed by user&amp;nbsp;arbitrarily&lt;/P&gt;
&lt;P&gt;2) There can be several time dimesions (day, week, month, ...), which are chosen by user&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>Fri, 18 Feb 2022 06:06:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Getting-sum-of-goods-for-the-first-date-of-each-month/m-p/1894071#M1217426</guid>
      <dc:creator>chetverikov</dc:creator>
      <dc:date>2022-02-18T06:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Getting sum of goods for the first date of each month</title>
      <link>https://community.qlik.com/t5/QlikView/Getting-sum-of-goods-for-the-first-date-of-each-month/m-p/1894260#M1217436</link>
      <description>&lt;P&gt;Hi Chetverikov,&lt;/P&gt;
&lt;P&gt;try mapping your min Dates in your Loadscript like this to get themin date for your GoodId in each month:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MinDates:
Mapping Load
	Date(Min(%Date)) &amp;amp; '_' &amp;amp; %Month &amp;amp; '_' &amp;amp; %GoodId as minDate,
	1 as flag
Resident Test
Group by %GoodId, %Month;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then Reload your table and apply this map like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Table:
Load
*,
ApplyMap('minDates', Date(%Date) &amp;amp; '_' &amp;amp; %Month &amp;amp; '_' %GoodId, 0) as flag
Resident....&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way you can use the following set expression in your calculation:&lt;/P&gt;
&lt;P&gt;Sum({$&amp;lt;flag = {1}&amp;gt;}%Count) to get your result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know if it helped,&lt;/P&gt;
&lt;P&gt;Can&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 11:39:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Getting-sum-of-goods-for-the-first-date-of-each-month/m-p/1894260#M1217436</guid>
      <dc:creator>canerkan</dc:creator>
      <dc:date>2022-02-17T11:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Getting sum of goods for the first date of each month</title>
      <link>https://community.qlik.com/t5/QlikView/Getting-sum-of-goods-for-the-first-date-of-each-month/m-p/1894623#M1217460</link>
      <description>&lt;P&gt;Thanks for your reply, Canerkan&lt;/P&gt;
&lt;P&gt;This does not work in my case, because data period can change arbitrarily after script loading, sorry that I have not metioned it. And if I would have several time dimensions (day, week, month, quarter, year), which could be turned on/off dynamically by user, I should keep several mapping tables and handle all the combinations of the dimensions. I want to find some solution for the problem: while aggregating data in rows of a table, take sum of goods count with a minumum date of a group. It sounds simple (for example, SQL has window functions for that), but still I am struggling.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have also tried: &lt;STRONG&gt;SUM(if(%Date=min(%Date),%Count,0))&lt;/STRONG&gt;&amp;nbsp;and I had an attempt to save &lt;STRONG&gt;min(%Date)&lt;/STRONG&gt; into another column - nothing has helped&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 06:18:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Getting-sum-of-goods-for-the-first-date-of-each-month/m-p/1894623#M1217460</guid>
      <dc:creator>chetverikov</dc:creator>
      <dc:date>2022-02-18T06:18:37Z</dc:date>
    </item>
  </channel>
</rss>

