<?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 Create New Filed in Data Load in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Create-New-Filed-in-Data-Load/m-p/2512847#M105263</link>
    <description>&lt;P&gt;Hi Friends&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have below dataset in my qlikview file and I want add new field(Flag) in my data load script. In this script I need add flag field as follows .&lt;/P&gt;&lt;P&gt;I same policy no continues for 3 continuous years I want flag to be '3NP' if two years '2NP' else 'NA' and all this particular Flag should be recorded all records. I have shown expected result next to my data set. Kindly help me to write the script please.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Upali_Wijearatne_0-1743653544063.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/179268i32D7042B281C6B9A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Upali_Wijearatne_0-1743653544063.png" alt="Upali_Wijearatne_0-1743653544063.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Apr 2025 04:15:03 GMT</pubDate>
    <dc:creator>Upali_Wijearatne</dc:creator>
    <dc:date>2025-04-03T04:15:03Z</dc:date>
    <item>
      <title>Create New Filed in Data Load</title>
      <link>https://community.qlik.com/t5/App-Development/Create-New-Filed-in-Data-Load/m-p/2512847#M105263</link>
      <description>&lt;P&gt;Hi Friends&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I have below dataset in my qlikview file and I want add new field(Flag) in my data load script. In this script I need add flag field as follows .&lt;/P&gt;&lt;P&gt;I same policy no continues for 3 continuous years I want flag to be '3NP' if two years '2NP' else 'NA' and all this particular Flag should be recorded all records. I have shown expected result next to my data set. Kindly help me to write the script please.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Upali_Wijearatne_0-1743653544063.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/179268i32D7042B281C6B9A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Upali_Wijearatne_0-1743653544063.png" alt="Upali_Wijearatne_0-1743653544063.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 04:15:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Create-New-Filed-in-Data-Load/m-p/2512847#M105263</guid>
      <dc:creator>Upali_Wijearatne</dc:creator>
      <dc:date>2025-04-03T04:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Filed in Data Load</title>
      <link>https://community.qlik.com/t5/App-Development/Create-New-Filed-in-Data-Load/m-p/2512901#M105272</link>
      <description>&lt;P&gt;Hi, if the same policy is interrupted for a year it could be more complicated, if not you can count the distintc year for each policy_no and the do a left join&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Left Join ([PolicyTable])
LOAD Policy_No,
  If(tmpCount=1, 'NA', tmpCount &amp;amp;'NP') as Flag
;
LOAD Policy_No,
  Count(Year) as tmpCount
Resident [PolicyTable]
Group by Policy_No;&lt;/LI-CODE&gt;&lt;P&gt;If it can be interrupted you will need a sorted load by Policy_No and Year, each row checking if the previuos is the same policy and year-1, if it is, then add one to tmpCount, else it starts again on 1:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;tmpCount:
LOAD Policy_No,
  Year
  If(Peek('Policy_No')=Policy_No and Peek('Year')=Year-1
    ,Peek(tmpCount)+1
    ,1) as tmpCount
Resident [PolicyTable]
Order by Policy_No, Year;&lt;/LI-CODE&gt;&lt;P&gt;And then you'll need to load by year descendat to apply the largest&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Left Join ([PolicyTable])
LOAD Policy_No,
  Year,
  If(Peek('Policy_No')=Policy_No and Peek('Year')=Year+1
    ,Peek('Flag')
    ,If(tmpCount=1
      ,'NA'
      ,'NP'&amp;amp; tmpCount)) as Flag
Resident [PolicyTable]
Order by Policy_No, Year desc;&lt;/LI-CODE&gt;&lt;P&gt;I didn't tested, maybe I missed something on the logic.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 09:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Create-New-Filed-in-Data-Load/m-p/2512901#M105272</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2025-04-03T09:16:04Z</dc:date>
    </item>
  </channel>
</rss>

