<?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: FirstSortedValue - for 2 dimensions in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/FirstSortedValue-for-2-dimensions/m-p/2097594#M89891</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/37110"&gt;@cristianj23a&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I like it! thanks a lot!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jul 2023 20:34:00 GMT</pubDate>
    <dc:creator>dana</dc:creator>
    <dc:date>2023-07-26T20:34:00Z</dc:date>
    <item>
      <title>FirstSortedValue - for 2 dimensions</title>
      <link>https://community.qlik.com/t5/App-Development/FirstSortedValue-for-2-dimensions/m-p/2097561#M89889</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT:&lt;/P&gt;
&lt;P&gt;Hi People,&lt;/P&gt;
&lt;P&gt;I have a change log of&amp;nbsp; incidents with user and update DateTime.&lt;/P&gt;
&lt;P&gt;Each incident has multiple records.&lt;/P&gt;
&lt;P&gt;For each incident,&amp;nbsp; I want to have only one record, with the first update.&lt;/P&gt;
&lt;P&gt;So my final record includes the fields:&lt;/P&gt;
&lt;P&gt;Incident No,&amp;nbsp; First Update (DateTime) , User&lt;/P&gt;
&lt;P&gt;The solution I found works, but not sure is optimal..&lt;/P&gt;
&lt;P&gt;Would appreciate&amp;nbsp; some feedback..&lt;/P&gt;
&lt;DIV&gt;TMP2_Incident_Audit:&lt;/DIV&gt;
&lt;DIV&gt;Load&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; IncidentID,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Timestamp(Min(UpdatedOn)) As FirstUpdatedOn,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; UserId&lt;/DIV&gt;
&lt;DIV&gt;Resident TMP1_Incident_Audit&lt;/DIV&gt;
&lt;DIV&gt;Group By IncidentID,UserId;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;inner Join (TMP2_Incident_Audit)&lt;/DIV&gt;
&lt;DIV&gt;Load&lt;/DIV&gt;
&lt;DIV&gt;IncidentID,&lt;/DIV&gt;
&lt;DIV&gt;FirstSortedValue(UserId,FirstUpdatedOn) As UserId&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Resident TMP2_Incident_Audit&lt;/DIV&gt;
&lt;DIV&gt;Group By IncidentID;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 17:47:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/FirstSortedValue-for-2-dimensions/m-p/2097561#M89889</guid>
      <dc:creator>dana</dc:creator>
      <dc:date>2023-07-26T17:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: FirstSortedValue - for 2 dimensions</title>
      <link>https://community.qlik.com/t5/App-Development/FirstSortedValue-for-2-dimensions/m-p/2097591#M89890</link>
      <description>&lt;P&gt;Hi, your current solution looks fine and should work as expected, but there are a couple of things that could be optimized.&lt;/P&gt;
&lt;P&gt;Avoid unnecessary Resident Load: You don't need to load the data into TMP2_Incident_Audit twice. Instead, you can calculate FirstUpdatedOn and UserId for each IncidentID in one single load.&lt;/P&gt;
&lt;P&gt;Min() and FirstSortedValue() together: There is a possibility of getting incorrect UserId if you have more than one UserId for the same minimum UpdatedOn timestamp for a given IncidentID. To mitigate this, you can concatenate UpdatedOn and UserId into a single field, and then use FirstSortedValue() to get the UserId for the first update.&lt;/P&gt;
&lt;P&gt;Here's a possible alternative approach:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;TMP2_Incident_Audit:&lt;BR /&gt;Load&lt;BR /&gt;IncidentID,&lt;BR /&gt;Timestamp(Min(UpdatedOn)) As FirstUpdatedOn,&lt;BR /&gt;FirstSortedValue(UserId &amp;amp; '|' &amp;amp; UpdatedOn, UpdatedOn) As FirstUserId&lt;BR /&gt;Resident TMP1_Incident_Audit&lt;BR /&gt;Group By IncidentID;&lt;/P&gt;
&lt;P&gt;Final_Incident_Audit:&lt;BR /&gt;Load&lt;BR /&gt;IncidentID,&lt;BR /&gt;FirstUpdatedOn,&lt;BR /&gt;SubField(FirstUserId, '|', 1) As UserId&lt;BR /&gt;Resident TMP2_Incident_Audit;&lt;/P&gt;
&lt;P&gt;Drop Table TMP2_Incident_Audit;&lt;/P&gt;
&lt;P&gt;In this approach, the FirstUserId field in the TMP2_Incident_Audit table is a combination of UserId and UpdatedOn. In the Final_Incident_Audit table, we extract the UserId from FirstUserId using the SubField() function.&lt;/P&gt;
&lt;P&gt;This solution should give you the desired result and it also eliminates the need for the inner join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarts.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 20:23:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/FirstSortedValue-for-2-dimensions/m-p/2097591#M89890</guid>
      <dc:creator>cristianj23a</dc:creator>
      <dc:date>2023-07-26T20:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: FirstSortedValue - for 2 dimensions</title>
      <link>https://community.qlik.com/t5/App-Development/FirstSortedValue-for-2-dimensions/m-p/2097594#M89891</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/37110"&gt;@cristianj23a&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I like it! thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 20:34:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/FirstSortedValue-for-2-dimensions/m-p/2097594#M89891</guid>
      <dc:creator>dana</dc:creator>
      <dc:date>2023-07-26T20:34:00Z</dc:date>
    </item>
  </channel>
</rss>

