<?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: Re: Script Error in forming new table in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787178#M665627</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, but it does not seem to work.&amp;nbsp; Here I have attached a highly reduced qvw that shows the data.&amp;nbsp; I would like the second table to be a single entry of each id with the latest State_TS and the associated State_Name.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 06 Dec 2014 00:22:55 GMT</pubDate>
    <dc:creator />
    <dc:date>2014-12-06T00:22:55Z</dc:date>
    <item>
      <title>Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787176#M665625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am relatively new to QlikView and even DB queries.&amp;nbsp; I am having a problem that I get a script error that I do not understand.&amp;nbsp; Basically, I am trying to create a new table from a resident one using a "where" clause.&amp;nbsp; Here is the simplified script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Start Script&lt;/P&gt;&lt;P&gt;State:&lt;/P&gt;&lt;P&gt;Load id,&lt;/P&gt;&lt;P&gt;state_id as CRS_ID,&lt;/P&gt;&lt;P&gt;state_date as State_TS;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This is a timestamp and has multiple entries per id&lt;/P&gt;&lt;P&gt;SQL SELECT *&lt;/P&gt;&lt;P&gt;FROM mydb.`cr_state`;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left Join (State)&lt;/P&gt;&lt;P&gt;Load state_id as CRS_ID,&lt;/P&gt;&lt;P&gt;name as State_Name;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This is a string that has an entry for each state_id&lt;/P&gt;&lt;P&gt;SQL SELECT *&lt;/P&gt;&lt;P&gt;FROM mydb.state;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Drop Field CRS_ID From CR_State;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Everything is fine to this point.&amp;nbsp; The table "State" looks good&lt;/P&gt;&lt;P&gt;//Now I want to create a new table with only the latest state based on the "latest" timestamp on each record&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Latest:&lt;/P&gt;&lt;P&gt;load id,&lt;/P&gt;&lt;P&gt;State_Name as Latest_State&lt;/P&gt;&lt;P&gt;State_TS as Latest_TS&lt;/P&gt;&lt;P&gt;resident State where State_TS = max(Latest_TS);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// End Script&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get an error in the log "General Script Error".&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&amp;nbsp; Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 19:13:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787176#M665625</guid>
      <dc:creator />
      <dc:date>2014-12-05T19:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787177#M665626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;John,&lt;/P&gt;&lt;P&gt;The problem is with your Max(Latest_TS).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm assuming you wan to the Max value of your State Timestamp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You'll want to crete a variable that stores the max value and use that variable in your where clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;tmp:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LOAD&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Max&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;State_TS&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Max_TS&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;RESIDENT&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; State;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;LET&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;vMax_TS&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;peek&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;('Max_TS');&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style=": ; color: #0000ff; font-size: 8pt;"&gt;DROP&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Table&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; tmp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where State_TS = $(vMax_TS)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck&lt;/P&gt;&lt;P&gt;Oscar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 19:53:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787177#M665626</guid>
      <dc:creator>oscar_ortiz</dc:creator>
      <dc:date>2014-12-05T19:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787178#M665627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, but it does not seem to work.&amp;nbsp; Here I have attached a highly reduced qvw that shows the data.&amp;nbsp; I would like the second table to be a single entry of each id with the latest State_TS and the associated State_Name.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Dec 2014 00:22:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787178#M665627</guid>
      <dc:creator />
      <dc:date>2014-12-06T00:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787179#M665628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tmp:&lt;/P&gt;&lt;P&gt;Load &lt;/P&gt;&lt;P&gt;&amp;nbsp; Max( State_TS ) As MaxTS&lt;/P&gt;&lt;P&gt;resident State;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let vMaxTS = peek('MaxTS');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Latest:&lt;/P&gt;&lt;P&gt;load &lt;/P&gt;&lt;P&gt;&amp;nbsp; cr_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; State_Name as Latest_State,&lt;/P&gt;&lt;P&gt;&amp;nbsp; State_TS as Latest_TS&lt;/P&gt;&lt;P&gt;resident State &lt;/P&gt;&lt;P&gt;where &lt;/P&gt;&lt;P&gt;&amp;nbsp; Exists( MaxTS, State_TS )&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DROP Table tmp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There was an issue with the number being stored in the variable.&amp;nbsp; So I changed things up a bit.&amp;nbsp; Instead of comparing against the variable I used the where Exists.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Give it a try and let me know if you have more issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good Luck&lt;/P&gt;&lt;P&gt;Oscar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Dec 2014 01:26:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787179#M665628</guid>
      <dc:creator>oscar_ortiz</dc:creator>
      <dc:date>2014-12-06T01:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787180#M665629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your efforts.&amp;nbsp; Unfortunately, it is taking the max of all of the records, which is the last cr_id, and that is the only cr_id that has values for Latest_TS and Latest_State.&amp;nbsp; Attached is hand edited excel file of a few records of what I am trying to get.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Dec 2014 02:20:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787180#M665629</guid>
      <dc:creator />
      <dc:date>2014-12-06T02:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787181#M665630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tab1:&lt;/P&gt;&lt;P&gt;LOAD *,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Timestamp#(Latest_TS,'DD-MM-YYYY hh:mm') AS Latest_TS1;&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cr_id, Latest_State, Latest_TS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40000, In-Progress, 14-11-2014 14:16&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40001, Open, 28-10-2014 19:28&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40002, In-Progress, 13-11-2014 19:39&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40006, In-Progress, 03-11-2014 22:31&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40007, Closed, 31-10-2014 9:15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40008, Open, 29-10-2014 2:05&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40009, Open, 29-10-2014 3:07&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40010, In-Progress, 14-11-2014 14:17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40011, Closed, 31-10-2014 9:14&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40012, Analysis, 18-11-2014 11:07&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40013, In-Progress, 14-11-2014 14:18&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40014, In-Progress, 13-11-2014 14:33&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40014, Analysis, 13-11-2014 15:33&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40014, Close5, 13-11-2014 16:33&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40015, Closed, 29-10-2014 16:22&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tab2:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; cr_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Timestamp(Max(Latest_TS1),'DD-MM-YYYY hh:mm') AS Max_Latest_TS&lt;/P&gt;&lt;P&gt;RESIDENT tab1&lt;/P&gt;&lt;P&gt;GROUP BY cr_id;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INNER JOIN(tab1)&lt;/P&gt;&lt;P&gt;LOAD cr_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Max_Latest_TS AS Latest_TS1&lt;/P&gt;&lt;P&gt;RESIDENT tab2;&lt;/P&gt;&lt;P&gt;DROP TABLE tab2; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: Have added 2 records to create multiple states:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40014, Analysis, 13-11-2014 15:33&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40014, Close5, 13-11-2014 16:33&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vivek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Dec 2014 11:42:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787181#M665630</guid>
      <dc:creator>vivek_niti</dc:creator>
      <dc:date>2014-12-06T11:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787182#M665631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can use peek to understand when the id change and order by to decide which id you want to keep (max or min state)&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;New: &lt;/P&gt;&lt;P&gt;NoConcatenate Load &lt;/P&gt;&lt;P&gt;id,&lt;/P&gt;&lt;P&gt;State_Name as max_State_Name,&lt;/P&gt;&lt;P&gt;State_TS as max_State_TS&lt;/P&gt;&lt;P&gt;Resident State&lt;/P&gt;&lt;P&gt;where &lt;STRONG&gt;Peek&lt;/STRONG&gt;(id) &amp;lt;&amp;gt; id&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;order by id, State_TS desc&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Dec 2014 14:00:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787182#M665631</guid>
      <dc:creator>maxgro</dc:creator>
      <dc:date>2014-12-06T14:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script Error in forming new table</title>
      <link>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787183#M665632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may reload the table with a new sorting-order: key and date descending. Then each record, where the key is different from the previous one, is the first one with a new key - sorting by date DESC it has to be always the latest one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TableSorted:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;Key,&lt;/P&gt;&lt;P&gt;Date,&lt;/P&gt;&lt;P&gt;IF(Key &amp;lt;&amp;gt; PEEK(Key, -1), 'I am the last')&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AS Indicator&lt;/P&gt;&lt;P&gt;RESIDENT&lt;/P&gt;&lt;P&gt;MyTable&lt;/P&gt;&lt;P&gt;ORDER BY&lt;/P&gt;&lt;P&gt;Key,&lt;/P&gt;&lt;P&gt;Date DESC;&lt;/P&gt;&lt;P&gt;DROP TABLE MyTable;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TableFiltered:&lt;/P&gt;&lt;P&gt;NOCONCATENATE LOAD * RESIDENT TableSorted WHERE Indicator = 'I am the last';&lt;/P&gt;&lt;P&gt;DROP TABLE TableSorted;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Dec 2014 19:02:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-Error-in-forming-new-table/m-p/787183#M665632</guid>
      <dc:creator>prieper</dc:creator>
      <dc:date>2014-12-07T19:02:47Z</dc:date>
    </item>
  </channel>
</rss>

