<?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: Group and get latest classification of a week in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Group-and-get-latest-classification-of-a-week/m-p/2445343#M97639</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;To do this you can use the&amp;nbsp;&lt;A href="https://help.qlik.com/en-US/sense/February2024/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/firstsorted.htm" target="_self"&gt;FirstSortedValue&lt;/A&gt;&amp;nbsp;function. It allows you to take the first result according to an aggregation and a sorting order.&lt;/P&gt;
&lt;P&gt;Here's an example script to adapt to your needs&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;//Load data and create week field / new Key
INPUT:
Load
	*,
    WeekName(Date) as [Week], //Create field Week
    [Key]&amp;amp;'|'&amp;amp;WeekName(Date) as [Key_Week]; //Create a key to join the new result table
Load
	[Key],
    timestamp(timestamp#([Date],'M/D/YYYY')) as [Date],
    [Class];
Load * inline [
	Key, Date, Class
	1, 3/10/2024, A
	2, 3/11/2024, D
	3, 3/12/2024, B
	4, 3/13/2024, C
	5, 3/14/2024, C
	1, 3/11/2024, B
	2, 3/12/2024, D
	3, 3/13/2024, A
	4, 3/14/2024, C
	5, 3/15/2024, A
	1, 3/12/2024, C
	2, 3/13/2024, D
	3, 3/14/2024, C
	4, 3/15/2024, C
	5, 3/16/2024, A
	1, 3/13/2024, D
	2, 3/14/2024, A
	4, 3/16/2024, C
	5, 3/17/2024, A
	1, 3/18/2024, A
	2, 3/19/2024, B
	3, 3/20/2024, C
];

//New table
OUTPUT:
Load
	[Key_Week], 
    FirstSortedValue([Class],-[Date]) as [Last Class] //-[Date] for the latest date
Resident INPUT
group by [Key_Week];&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 26 Apr 2024 14:55:23 GMT</pubDate>
    <dc:creator>Pierrick</dc:creator>
    <dc:date>2024-04-26T14:55:23Z</dc:date>
    <item>
      <title>Group and get latest classification of a week</title>
      <link>https://community.qlik.com/t5/App-Development/Group-and-get-latest-classification-of-a-week/m-p/2445292#M97635</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please refer to snapshot , the input table has dates and classification column along with other columns. I want to create this shown output where latest classification is selected for each key as per week&lt;/P&gt;
&lt;P&gt;note: week starts on Mon and ends on Sun. And I have highlighted dates falling in same week.&lt;/P&gt;
&lt;P&gt;I want to do it at script level only.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="IMG_4892.jpeg" style="width: 5712px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/164790i06043824C996A96B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="IMG_4892.jpeg" alt="IMG_4892.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 13:11:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Group-and-get-latest-classification-of-a-week/m-p/2445292#M97635</guid>
      <dc:creator>Anku</dc:creator>
      <dc:date>2024-04-26T13:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Group and get latest classification of a week</title>
      <link>https://community.qlik.com/t5/App-Development/Group-and-get-latest-classification-of-a-week/m-p/2445343#M97639</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;To do this you can use the&amp;nbsp;&lt;A href="https://help.qlik.com/en-US/sense/February2024/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/firstsorted.htm" target="_self"&gt;FirstSortedValue&lt;/A&gt;&amp;nbsp;function. It allows you to take the first result according to an aggregation and a sorting order.&lt;/P&gt;
&lt;P&gt;Here's an example script to adapt to your needs&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;//Load data and create week field / new Key
INPUT:
Load
	*,
    WeekName(Date) as [Week], //Create field Week
    [Key]&amp;amp;'|'&amp;amp;WeekName(Date) as [Key_Week]; //Create a key to join the new result table
Load
	[Key],
    timestamp(timestamp#([Date],'M/D/YYYY')) as [Date],
    [Class];
Load * inline [
	Key, Date, Class
	1, 3/10/2024, A
	2, 3/11/2024, D
	3, 3/12/2024, B
	4, 3/13/2024, C
	5, 3/14/2024, C
	1, 3/11/2024, B
	2, 3/12/2024, D
	3, 3/13/2024, A
	4, 3/14/2024, C
	5, 3/15/2024, A
	1, 3/12/2024, C
	2, 3/13/2024, D
	3, 3/14/2024, C
	4, 3/15/2024, C
	5, 3/16/2024, A
	1, 3/13/2024, D
	2, 3/14/2024, A
	4, 3/16/2024, C
	5, 3/17/2024, A
	1, 3/18/2024, A
	2, 3/19/2024, B
	3, 3/20/2024, C
];

//New table
OUTPUT:
Load
	[Key_Week], 
    FirstSortedValue([Class],-[Date]) as [Last Class] //-[Date] for the latest date
Resident INPUT
group by [Key_Week];&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 26 Apr 2024 14:55:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Group-and-get-latest-classification-of-a-week/m-p/2445343#M97639</guid>
      <dc:creator>Pierrick</dc:creator>
      <dc:date>2024-04-26T14:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: Group and get latest classification of a week</title>
      <link>https://community.qlik.com/t5/App-Development/Group-and-get-latest-classification-of-a-week/m-p/2446161#M97680</link>
      <description>&lt;P&gt;Hi, thanks for your response. I can still see more than 1 class for a key.&lt;/P&gt;
&lt;P&gt;I am looking for a solution where I can have &lt;STRONG&gt;latest&lt;/STRONG&gt; class value for its respective key falling within a week.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 08:58:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Group-and-get-latest-classification-of-a-week/m-p/2446161#M97680</guid>
      <dc:creator>Anku</dc:creator>
      <dc:date>2024-04-29T08:58:09Z</dc:date>
    </item>
  </channel>
</rss>

