<?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 How to update previous row after comparing with current and previous row? in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350924#M117686</link>
    <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi, i need to update previous row values after comparing with current and previous row. I am using tMemorizeRows for saving the previous row and tJavaFlex for comparing the previous row with the current row but i was not able to update the previous row with new values. How can i do it?&lt;/P&gt;</description>
    <pubDate>Fri, 15 Nov 2024 21:38:37 GMT</pubDate>
    <dc:creator>SSingh1687332860</dc:creator>
    <dc:date>2024-11-15T21:38:37Z</dc:date>
    <item>
      <title>How to update previous row after comparing with current and previous row?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350924#M117686</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi, i need to update previous row values after comparing with current and previous row. I am using tMemorizeRows for saving the previous row and tJavaFlex for comparing the previous row with the current row but i was not able to update the previous row with new values. How can i do it?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 21:38:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350924#M117686</guid>
      <dc:creator>SSingh1687332860</dc:creator>
      <dc:date>2024-11-15T21:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to update previous row after comparing with current and previous row?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350925#M117687</link>
      <description>&lt;P&gt;Hi @Sunny Singh​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tMemorizeRows only stores a photography of previous rows, so any changes you make on its array won't affect the actual rows as they already went through the component.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd suggest you try using tHashOutput after tJavaFlex, set a key on your schema if not already and set tHashOutput to "Keep last" on key management. This way you'll will be able to output previous row again and simulate a update behavior by keeping only last row based on its key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then you use tHashInput on a second subjob to read wha'ts stored in memory.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 03:29:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350925#M117687</guid>
      <dc:creator>anselmopeixoto</dc:creator>
      <dc:date>2023-06-27T03:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to update previous row after comparing with current and previous row?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350926#M117688</link>
      <description>&lt;P&gt;Thank you for your answer @Anselmo Peixoto​&amp;nbsp;. There is a way to select the row to outoput (current o previous) based on a condition in tHashOutput&amp;nbsp;o tJavaFlex?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;if(condition) &lt;/P&gt;&lt;P&gt; output current row&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt; output previous row&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 07:41:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350926#M117688</guid>
      <dc:creator>SSingh1687332860</dc:creator>
      <dc:date>2023-06-27T07:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to update previous row after comparing with current and previous row?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350927#M117689</link>
      <description>&lt;P&gt;Hi @Sunny Singh​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say you have a job like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input -row1-&amp;gt; tMemorizeRows -row2-&amp;gt; tJavaFlex -row3-&amp;gt; tHashOutput&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when current row reaches tJavaFlex, the previous row were already sent to its output in last iteration, so it will be already stored in tHashOutput.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this reason, what I suggest is that you replace the previous row stored in tHashOutput based on its schema key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On tJavaFlex main code you can write a condition like in your example, but in those cases you want to output previous row, you actually replace current row key with the same key as previous row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if(condition) //add a new row to tHashOutput&lt;/P&gt;&lt;P&gt;row3.key_column = row2.key_column;&lt;/P&gt;&lt;P&gt;row3.another_column = row2.another_column;&lt;/P&gt;&lt;P&gt;else //replace previous row&lt;/P&gt;&lt;P&gt;row3.key_column = key_column_tMemorizeRows[1]; //last row key&lt;/P&gt;&lt;P&gt;row3.another_column = row2.another_column; //you can update values for other columns in previous row if you want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now considering that previous row is already in tHashOutput, if you don't want to update any column for that row, you can just use the "continue;" keyword in your condition. This will make the loop "jump" to next iteration without the need of a output row.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 13:47:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350927#M117689</guid>
      <dc:creator>anselmopeixoto</dc:creator>
      <dc:date>2023-06-27T13:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to update previous row after comparing with current and previous row?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350928#M117690</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.talend.com/s/profile/00539000003YjlpAAC" alt="https://community.talend.com/s/profile/00539000003YjlpAAC" target="_blank"&gt;@anselmopeixoto&lt;/A&gt;&amp;nbsp;(Customer)​&lt;/P&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;i tried all the steps you suggested but it didn't work. Maybe i made some mistakes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Job: input -row1-&amp;gt; tMemorizeRows -row2-&amp;gt; tJavaFlex -row3-&amp;gt; tHashOutput&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code in tJavaFlex:&lt;/P&gt;&lt;P&gt;Start code:&lt;/P&gt;&lt;P&gt;int cont = 0;&lt;/P&gt;&lt;P&gt;Date date_start = new Date();&lt;/P&gt;&lt;P&gt;Date date_end = new Date();&lt;/P&gt;&lt;P&gt;SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Main code:&lt;/P&gt;&lt;P&gt;if(row1.A == last_a &amp;amp;&amp;amp; row1.Year == last_year &amp;amp;&amp;amp; row2.C.equals(last_c) &amp;amp;&amp;amp; row1.D.equals(last_d) &amp;amp;&amp;amp; row1.E.equals(last_e)) {&lt;/P&gt;&lt;P&gt;if(!row1.F &amp;amp;&amp;amp; cont == 0) {&lt;/P&gt;&lt;P&gt;//do nothing&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else if(row1.F) {&lt;/P&gt;&lt;P&gt;date_end = TalendDate.addDate(format.parse("31-12-"+row1.Year), row1.Months*-1, "MM");&lt;/P&gt;&lt;P&gt;//PreviousRow&lt;/P&gt;&lt;P&gt;date_start = TalendDate.addDate(date_end, Months_tMemorizeRows_1[1]*-1, "MM");&lt;/P&gt;&lt;P&gt;date_start = TalendDate.addDate(date_start, 1, "dd");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;row2.KeyColumn = KeyColumn_tMemorizeRows_1[1];&amp;nbsp;&lt;/P&gt;&lt;P&gt;row2.DateStart = date_start; //-&amp;gt; update DateStart in the previous row&lt;/P&gt;&lt;P&gt;row2.DateEnd = date_end; //-&amp;gt; update DateEnd in the previous row&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cont = 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else if(!row1.F) {&lt;/P&gt;&lt;P&gt;//PreviousRow&lt;/P&gt;&lt;P&gt;date_start = format.parse("01-01-"+ Year_tMemorizeRows_1[1]);&lt;/P&gt;&lt;P&gt;date_end = TalendDate.addDate(date_start, Months_tMemorizeRows_1[1], "MM");&lt;/P&gt;&lt;P&gt;date_end = TalendDate.addDate(date_end, -1, "dd");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;row2.KeyColumn = KeyColumn_tMemorizeRows_1[1];&amp;nbsp;&lt;/P&gt;&lt;P&gt;row2.DateStart = date_start; //-&amp;gt; update DateStart in the previous row&lt;/P&gt;&lt;P&gt;row2.DateEnd = date_end; //-&amp;gt; update DateEnd in the previous row&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;//CurrentRow&lt;/P&gt;&lt;P&gt;date_end = TalendDate.addDate(date_end, 1, "dd");&lt;/P&gt;&lt;P&gt;date_end = TalendDate.addDate(date_start, row1.Months, "MM");&lt;/P&gt;&lt;P&gt;date_end = TalendDate.addDate(date_end, -1, "dd");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;row2.KeyColumn = row1.KeyColumn;&lt;/P&gt;&lt;P&gt;row2.DateStart = date_start; //-&amp;gt; update DateStart in the current row&lt;/P&gt;&lt;P&gt;row2.DateEnd = date_end; //-&amp;gt; update DateEnd in the current row&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cont = 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;cont++;&lt;/P&gt;&lt;P&gt;last_a = row1.A;&lt;/P&gt;&lt;P&gt;last_year = row1.Year;&lt;/P&gt;&lt;P&gt;last_c = row1.C;&lt;/P&gt;&lt;P&gt;last_d = row1.D;&lt;/P&gt;&lt;P&gt;last_e = row1.E&lt;/P&gt;&lt;P&gt;------------------------------------------------------------- End Code ----------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What can i do to fix the problem?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 12:39:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350928#M117690</guid>
      <dc:creator>SSingh1687332860</dc:creator>
      <dc:date>2023-06-29T12:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to update previous row after comparing with current and previous row?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350929#M117691</link>
      <description>&lt;P&gt;Hi @Sunny Singh​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I cannot test your code, but what caught my attention is that I didn't find where the last_a and other last* variables are being first declared/initialized.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps you can find out what is happening by replacing temporally the tHashMap by a tLogRow and limiting the input data to a sample, so you can investigate its behavior.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2023 19:14:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-to-update-previous-row-after-comparing-with-current-and/m-p/2350929#M117691</guid>
      <dc:creator>anselmopeixoto</dc:creator>
      <dc:date>2023-06-29T19:14:05Z</dc:date>
    </item>
  </channel>
</rss>

