<?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: Median of Latest Date for each product in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1555101#M440626</link>
    <description>Thank you explaining it so nicely. Have a great day/night.</description>
    <pubDate>Tue, 12 Mar 2019 03:40:12 GMT</pubDate>
    <dc:creator>montubhardwaj</dc:creator>
    <dc:date>2019-03-12T03:40:12Z</dc:date>
    <item>
      <title>Median of Latest Date for each product</title>
      <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554652#M440576</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I need your suggestions with this problem. Please refer to the attached qvw file. What is thew best way to find average and median for Latest Date Values (0.2,0.56,0.96) and Previous Date Values (0.25,0.59,0.66) for all the products. I was able to figure out Factor value for all products for latest and previous date but having trouble with average and median. I want the result to be displayed in a text box object.&lt;BR /&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 04:15:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554652#M440576</guid>
      <dc:creator>montubhardwaj</dc:creator>
      <dc:date>2019-03-11T04:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Median of Latest Date for each product</title>
      <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554653#M440577</link>
      <description>&lt;P&gt;&lt;A href="https://community.qlik.com/t5/user/viewprofilepage/user-id/22593" target="_blank"&gt;@rubenmarin&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp; maybe you have the answer already!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 04:13:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554653#M440577</guid>
      <dc:creator>montubhardwaj</dc:creator>
      <dc:date>2019-03-11T04:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Median of Latest Date for each product</title>
      <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554656#M440579</link>
      <description>&lt;P&gt;If you add&amp;nbsp; a vintage* value by product&amp;nbsp; then this becomes quite easy. The load script needs a small modification:&lt;/P&gt;&lt;PRE&gt;test1:
LOAD * ,
RowNo() As Row#
INLINE [
    Product, Factor, Date
    Product_A, 0.20, 1/3/2018
    Product_A, 0.25, 1/3/2018
    Product_A, 0.30, 1/2/2018
    Product_A, 0.35, 1/1/2018
    Product_B, 0.56, 12/3/2018
    Product_B, 0.59, 12/3/2018
    Product_B, 0.55, 12/2/2018
    Product_B, 0.86, 12/1/2018
    Product_C, 0.96, 2/3/2018
    Product_C, 0.66, 2/2/2018
    Product_C, 0.68, 2/2/2018
    Product_C, 0.99, 2/1/2018
];

Test2:
LOAD *,
	AutoNumber(Date + Row# / 1e6, Product) as Vintage
Resident test1
Order By Product, Date DESC;

DROP TABLE test1;&lt;/PRE&gt;&lt;P&gt;The auto number creates unique values for each product for the last date (=1) and the next last date (=2). So the average and median expression for the last date and the precious date would be:&lt;/P&gt;&lt;PRE&gt;=Avg({&amp;lt;Vintage={1}&amp;gt;} Factor)
=Median({&amp;lt;Vintage={1}&amp;gt;} Factor)&lt;BR /&gt;&lt;BR /&gt;=Avg({&amp;lt;Vintage={2}&amp;gt;} Factor) &lt;BR /&gt;=Median({&amp;lt;Vintage={2}&amp;gt;} Factor)&lt;/PRE&gt;&lt;P&gt;You could also simplify your sums:&lt;/P&gt;&lt;PRE&gt;=Sum({&amp;lt;Product={'Product_C'}, Vintage={1}&amp;gt;} Factor)&lt;/PRE&gt;&lt;P&gt;Note the row number is used to de-duplicate the dates, so if there are two value for the most recent date, the first loaded date will be used. If the intention was to get the sum / average and median for all the Factors for a product for the last date and previous date, then just use:&lt;/P&gt;&lt;PRE&gt;...
AutoNumber(Date, Product) as Vintage
...&lt;/PRE&gt;&lt;P&gt;in the script. The text box expressions would not need to be adjusted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* a sequence value that starts from the last date, incrementing the sequence by date working backwards (in this case).&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 04:59:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554656#M440579</guid>
      <dc:creator>jonathandienst</dc:creator>
      <dc:date>2019-03-11T04:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Median of Latest Date for each product</title>
      <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554663#M440580</link>
      <description>Wow, this is masterclass. Thanks much. Makes sense with the script. What if we only need to achieve it using expressions? I am just curious to see your solution.</description>
      <pubDate>Mon, 11 Mar 2019 05:25:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554663#M440580</guid>
      <dc:creator>montubhardwaj</dc:creator>
      <dc:date>2019-03-11T05:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Median of Latest Date for each product</title>
      <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554664#M440581</link>
      <description>Also if you can explain little about the concept you used in Autonumber, that would be very helpful &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/14931"&gt;@jonathandienst&lt;/a&gt;</description>
      <pubDate>Mon, 11 Mar 2019 05:33:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554664#M440581</guid>
      <dc:creator>montubhardwaj</dc:creator>
      <dc:date>2019-03-11T05:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: Median of Latest Date for each product</title>
      <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554899#M440597</link>
      <description>&lt;P&gt;I would not do this in expressions myself. while it may be possible, it will probably be quite complex.&amp;nbsp;&lt;/P&gt;&lt;P&gt;AutoNumber() used with two parameters will number the first parameter in a group made up of the second parameter. That sounds clunky, so let me try again. Each distinct value of parameter 2 makes up a new list starting at 1 and looks up and adds the next number in that list.&lt;/P&gt;&lt;P&gt;So here, there will be an autonumber sequence for each Product. Value = 1 would be the first date found for that order. Value = 2 will be the next, etc. The Order By will determine if you start with the smallest date or the largest date.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 14:24:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1554899#M440597</guid>
      <dc:creator>jonathandienst</dc:creator>
      <dc:date>2019-03-11T14:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Median of Latest Date for each product</title>
      <link>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1555101#M440626</link>
      <description>Thank you explaining it so nicely. Have a great day/night.</description>
      <pubDate>Tue, 12 Mar 2019 03:40:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Median-of-Latest-Date-for-each-product/m-p/1555101#M440626</guid>
      <dc:creator>montubhardwaj</dc:creator>
      <dc:date>2019-03-12T03:40:12Z</dc:date>
    </item>
  </channel>
</rss>

