<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>extract highest row from array</title><link>https://community.appian.com/discussions/f/data/20538/extract-highest-row-from-array</link><description>Team, 
 I have an array of results from query and want to use the rows which have latest timestamp. 
 So array have data like (username :abc,id,1,timestamp1) , same user have another entry but with different timestamp. Max is not doing the trick , any</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: extract highest row from array</title><link>https://community.appian.com/thread/80061?ContentTypeID=1</link><pubDate>Thu, 04 Mar 2021 22:41:33 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b9f39b04-8779-4b8b-b022-a0c836bf8c12</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;Yeah this will only work if it&amp;#39;s actually a timestamp - there isn&amp;#39;t a concept of a &amp;quot;MAX&amp;quot; for a text field, so it wouldn&amp;#39;t be supported. Can you update the column in the database to use a timezone instead? I also don&amp;#39;t think your filters are going to work if it&amp;#39;s actually stored in the database as a text type.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: extract highest row from array</title><link>https://community.appian.com/thread/80043?ContentTypeID=1</link><pubDate>Thu, 04 Mar 2021 18:09:48 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:cfa988d5-9a03-418b-b82a-75509ca810f0</guid><dc:creator>gauravp0003</dc:creator><description>&lt;p&gt;seems timestamp is getting stored in text format in DB and CDT is also having text&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: extract highest row from array</title><link>https://community.appian.com/thread/80042?ContentTypeID=1</link><pubDate>Thu, 04 Mar 2021 18:06:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1a9c2c59-7aa1-475a-b3e2-835d59175800</guid><dc:creator>gauravp0003</dc:creator><description>&lt;p&gt;Thank Peter. I have tried below code but it says MAX cannot be applied to timestamp (&lt;span&gt;Expression evaluation error at function a!queryEntity [line 2]: Cannot apply aggregation function [MAX] to field [timestamp]. The valid data types for [MAX] are [[Number (Integer), Number (Decimal), Interval (Day to Second), Boolean, Date, Date with Timezone, Date and Time, Date and Time with Timezone, Time]].&lt;/span&gt;)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If i change MAX with count it says (&lt;span&gt;Expression evaluation error at function a!queryEntity [line 2]: Cannot sort by [timestamp]. When grouping, provide the alias in order to sort by one of the grouped or aggregated fields.&lt;/span&gt;)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Snippet of code:&lt;/p&gt;
&lt;p&gt;In output i want (username,firstname,timestamp(latest),created) from view.&lt;/p&gt;
&lt;p&gt;with(&lt;br /&gt;a!queryEntity(&lt;br /&gt; entity: cons!VW,&lt;br /&gt; query: a!query(&lt;br /&gt; aggregation: a!queryAggregation(&lt;br /&gt; aggregationColumns:&lt;br /&gt; {&lt;br /&gt; a!queryAggregationColumn(&lt;br /&gt; field: &amp;quot;username&amp;quot;,&lt;br /&gt; isGrouping: true&lt;br /&gt; ),&lt;br /&gt; a!queryAggregationColumn(&lt;br /&gt; field: &amp;quot;timestamp&amp;quot;,&lt;br /&gt; alias:&amp;quot;last_login&amp;quot;,&lt;br /&gt; aggregationFunction: &amp;quot;COUNT&amp;quot;&lt;br /&gt; )&lt;br /&gt; }&lt;br /&gt; ),&lt;br /&gt; logicalExpression: a!queryLogicalExpression(&lt;br /&gt; operator: &amp;quot;AND&amp;quot;,&lt;br /&gt; filters: {&lt;br /&gt; a!queryFilter(&lt;br /&gt; field: &amp;quot;username&amp;quot;,&lt;br /&gt; operator: &amp;quot;in&amp;quot;,&lt;br /&gt; value: ri!user&lt;br /&gt; ),&lt;br /&gt; a!queryFilter(&lt;br /&gt; field: &amp;quot;timestamp&amp;quot;,&lt;br /&gt; operator: &amp;quot;&amp;gt;=&amp;quot;,&lt;br /&gt; value: ri!year &amp;amp; &amp;quot;-01-01 00:00:00&amp;quot;&lt;br /&gt; ),&lt;br /&gt; a!queryFilter(&lt;br /&gt; field: &amp;quot;timestamp&amp;quot;,&lt;br /&gt; operator: &amp;quot;&amp;lt;=&amp;quot;,&lt;br /&gt; value: ri!year &amp;amp; &amp;quot;-03-31 00:00:00&amp;quot;&lt;br /&gt; )&lt;br /&gt; }&lt;br /&gt; ),&lt;br /&gt; pagingInfo: a!pagingInfo(1,-1,a!sortInfo(&amp;quot;timestamp&amp;quot;,false))&lt;br /&gt; )&lt;br /&gt;)&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: extract highest row from array</title><link>https://community.appian.com/thread/80040?ContentTypeID=1</link><pubDate>Thu, 04 Mar 2021 17:28:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:54adb450-9d66-4eac-9b4a-ca8e0d3a8b23</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;You can do this using an aggregation. If you group by the username and return the MAX of the date, then it should return the most recent item. Here&amp;#39;s an example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!queryEntity(
  entity: cons!YOUR_DSE,
  query: a!query(
    aggregation: a!queryAggregation(
      aggregationColumns: {
        a!queryAggregationColumn(
          field: &amp;quot;username&amp;quot;,
          isGrouping: true
        ),
        a!queryAggregationColumn(
          field: &amp;quot;dateUpdated&amp;quot;,
          alias: &amp;quot;dateUpdated_max&amp;quot;,
          aggregationfunction: &amp;quot;MAX&amp;quot;,
        )
      }
    ),
    pagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: 50,
      sort: a!sortInfo(
        field: &amp;quot;dateUpdated_max&amp;quot;,
        ascending: false
      )
    )
  ),
  fetchTotalCount: false
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: extract highest row from array</title><link>https://community.appian.com/thread/80038?ContentTypeID=1</link><pubDate>Thu, 04 Mar 2021 17:01:08 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:40bfb198-e190-4821-bf4d-a88a4146d4d5</guid><dc:creator>gauravp0003</dc:creator><description>&lt;p&gt;Hello Manuel,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you . Yes , using sort info i am able to get the top rows sorted in order but as said there are many rows in returned dataset and i want the latest top rows out to show in grid as unique data else multiple users are appearing in grid , i want unique usernames with latest timestamp.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: extract highest row from array</title><link>https://community.appian.com/thread/80037?ContentTypeID=1</link><pubDate>Thu, 04 Mar 2021 16:59:07 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:efc7132e-9ad6-4fef-ad77-42756c6f159a</guid><dc:creator>ManuelHTG</dc:creator><description>&lt;p&gt;Does the Dataset comes from the DB?&lt;/p&gt;
&lt;p&gt;If yes, you can use a!paginginfo and with the a!sort get the data in chronological order.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>