<?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: (Tricky?) Scripting Question in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502092#M103419</link>
    <description>&lt;P&gt;Pretty sure what I'd do is:&lt;/P&gt;
&lt;P&gt;1) Get the max year for each contract (append it to the original table as max_year)&lt;/P&gt;
&lt;P&gt;left join(Original)&lt;/P&gt;
&lt;P&gt;Load contract_id, max(payment_year) as max_year&lt;/P&gt;
&lt;P&gt;Resident Original&lt;/P&gt;
&lt;P&gt;Group by contract_Id;&lt;/P&gt;
&lt;P&gt;2) Use a While loop to make one record per year:&lt;/P&gt;
&lt;P&gt;NewTable:&lt;/P&gt;
&lt;P&gt;Load contract_Id, contract_year, contract_year + iterno() -1 as payment_year, 0 as payment&lt;/P&gt;
&lt;P&gt;Resident Original&lt;/P&gt;
&lt;P&gt;While contract_year + iterno() - 1 &amp;lt;= max_year; // Double check this condition, I can't test it at the moment&lt;/P&gt;
&lt;P&gt;3) Group by the entire dimension list and sum the payments&lt;/P&gt;
&lt;P&gt;Final:&lt;/P&gt;
&lt;P&gt;Noconcatenate Load contract_id, contract_year, payment_year, sum(payment) as payment&lt;/P&gt;
&lt;P&gt;Resident Original&lt;/P&gt;
&lt;P&gt;Group by contract_id, contract_year, payment_year;&lt;/P&gt;
&lt;P&gt;4) Drop the tables we don't need anymore:&lt;/P&gt;
&lt;P&gt;Drop table Original;&lt;/P&gt;
&lt;P&gt;Drop Table NewTable;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jan 2025 19:21:21 GMT</pubDate>
    <dc:creator>Or</dc:creator>
    <dc:date>2025-01-20T19:21:21Z</dc:date>
    <item>
      <title>(Tricky?) Scripting Question</title>
      <link>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502034#M103406</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;
&lt;P&gt;i am facing the following challange. Given is the following sample data:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;TABLE border="1" width="80%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;contract_id&lt;/TD&gt;
&lt;TD width="20%"&gt;contract_year&lt;/TD&gt;
&lt;TD width="20%"&gt;payment_year&lt;/TD&gt;
&lt;TD width="20%"&gt;payment&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;ABC&lt;/TD&gt;
&lt;TD width="20%"&gt;2019&lt;/TD&gt;
&lt;TD width="20%"&gt;2019&lt;/TD&gt;
&lt;TD width="20%"&gt;$ 1000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;ABC&lt;/TD&gt;
&lt;TD width="20%"&gt;2019&lt;/TD&gt;
&lt;TD width="20%"&gt;2020&lt;/TD&gt;
&lt;TD width="20%"&gt;$ 250&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;ABC&lt;/TD&gt;
&lt;TD width="20%"&gt;2019&lt;/TD&gt;
&lt;TD width="20%"&gt;2021&lt;/TD&gt;
&lt;TD width="20%"&gt;$ 2000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;ABC&lt;/TD&gt;
&lt;TD width="20%"&gt;2019&lt;/TD&gt;
&lt;TD width="20%"&gt;2023&lt;/TD&gt;
&lt;TD width="20%"&gt;$ 250&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%"&gt;ABC&lt;/TD&gt;
&lt;TD width="20%"&gt;2019&lt;/TD&gt;
&lt;TD width="20%"&gt;2024&lt;/TD&gt;
&lt;TD width="20%"&gt;$ 2500&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ&lt;/TD&gt;
&lt;TD&gt;2021&lt;/TD&gt;
&lt;TD&gt;2021&lt;/TD&gt;
&lt;TD&gt;$ 100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ&lt;/TD&gt;
&lt;TD&gt;2021&lt;/TD&gt;
&lt;TD&gt;2022&lt;/TD&gt;
&lt;TD&gt;$ 250&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ&lt;/TD&gt;
&lt;TD&gt;2021&lt;/TD&gt;
&lt;TD&gt;2024&lt;/TD&gt;
&lt;TD&gt;$ 1200&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are contracts and in almost every year there is a payment regarding a given contract (&amp;gt;&amp;gt; payment year).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a pivot table that looks like this (the columns after Year ist the field payment_year):&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="11.11111111111111%"&gt;contract_id&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;contract_year&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;2019&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;2020&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;2021&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;2022&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;2023&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;2024&lt;/TD&gt;
&lt;TD width="11.11111111111111%"&gt;2025&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;TD&gt;$ 1000&lt;/TD&gt;
&lt;TD&gt;$ 250&lt;/TD&gt;
&lt;TD&gt;$ 2000&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;$ 2000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;$ 250&lt;/TD&gt;
&lt;TD&gt;$ 2500&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;$ 2500&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ&lt;/TD&gt;
&lt;TD&gt;2021&lt;/TD&gt;
&lt;TD&gt;$ 0&lt;/TD&gt;
&lt;TD&gt;$ 0&lt;/TD&gt;
&lt;TD&gt;$ 100&lt;/TD&gt;
&lt;TD&gt;$ 250&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;$ 250&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;$ 1200&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#FF0000"&gt;$ 1200&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The challange is as follows:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;my data has gaps. meaning: not every contract has a payment in every year up until current year, but i need to display consistent years as above&lt;/LI&gt;
&lt;LI&gt;where there is missing data after the first payment i need to populate the payment with the previous year's payment until a new record with payment (red colored amounts)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to do this with minimal scripting effort ? i have built a solution by creating fake records for every missing payment year per contract but this a very imperformant (&amp;gt; 90M contracts) and resulted in a lot of script which is hard to maintain. Is there a lean way of achieving what i am after ?&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 15:04:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502034#M103406</guid>
      <dc:creator>xyz_1011</dc:creator>
      <dc:date>2025-01-20T15:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: (Tricky?) Scripting Question</title>
      <link>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502046#M103408</link>
      <description>&lt;P&gt;It shouldn't be too complicated to fill in the gaps, and it shouldn't do too much to performance given how small this table is even if the number of rows is massive. What approach have you used to do this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 15:06:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502046#M103408</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2025-01-20T15:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: (Tricky?) Scripting Question</title>
      <link>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502048#M103409</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/6142"&gt;@Or&lt;/a&gt;&amp;nbsp;for your reply. The actual data set has appr. 25 columns and &amp;gt; 90M contracts and a multiple of this in records. I tried, without knowing best practice for this use case, to&lt;/P&gt;
&lt;P&gt;a) identify those contracts that have gaps and store them in a temp table&lt;/P&gt;
&lt;P&gt;b) in a loop generate dummy records for every missing contract and payment_year based on the temp table created in a) and bringing it back to the original table&lt;/P&gt;
&lt;P&gt;I am simply wondering if there is an easier / cleander way to do this...or how other users would aproach this exercise.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 15:19:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502048#M103409</guid>
      <dc:creator>xyz_1011</dc:creator>
      <dc:date>2025-01-20T15:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: (Tricky?) Scripting Question</title>
      <link>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502064#M103412</link>
      <description>&lt;P&gt;I'm not great a Qlik scripting.&amp;nbsp; I would do this sort of thing in a database sql call.&amp;nbsp; Are you using a database to store this data?&lt;/P&gt;
&lt;P&gt;I am including below how I would script this in a SQL statement.&amp;nbsp; The&amp;nbsp; particular syntax is specific to the database that I am using now, but many database engines support this kind of query today.&amp;nbsp; Perhaps you could translate this in a manner that your database engine could use?&amp;nbsp; &amp;nbsp;If you have multi-year gaps in your data, you could expand each case statement to cover multiple years of missing data.&lt;/P&gt;
&lt;P&gt;Maintenance is easy.&amp;nbsp; Just add a new case statement each year to cover the new year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The example attached creates a temp table and loads it with the sample data that you show above.&amp;nbsp; The big honking select statement pulls that temp data and formats as per your requested output.&lt;/P&gt;
&lt;P&gt;Syntax in the attached file.&lt;/P&gt;
&lt;P&gt;Don't let those SQL skills atrophy!&lt;/P&gt;
&lt;DIV&gt;I hope this helps,&lt;/DIV&gt;
&lt;DIV&gt;BuildItStrong&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 16:03:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502064#M103412</guid>
      <dc:creator>BuildItStrong</dc:creator>
      <dc:date>2025-01-20T16:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: (Tricky?) Scripting Question</title>
      <link>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502092#M103419</link>
      <description>&lt;P&gt;Pretty sure what I'd do is:&lt;/P&gt;
&lt;P&gt;1) Get the max year for each contract (append it to the original table as max_year)&lt;/P&gt;
&lt;P&gt;left join(Original)&lt;/P&gt;
&lt;P&gt;Load contract_id, max(payment_year) as max_year&lt;/P&gt;
&lt;P&gt;Resident Original&lt;/P&gt;
&lt;P&gt;Group by contract_Id;&lt;/P&gt;
&lt;P&gt;2) Use a While loop to make one record per year:&lt;/P&gt;
&lt;P&gt;NewTable:&lt;/P&gt;
&lt;P&gt;Load contract_Id, contract_year, contract_year + iterno() -1 as payment_year, 0 as payment&lt;/P&gt;
&lt;P&gt;Resident Original&lt;/P&gt;
&lt;P&gt;While contract_year + iterno() - 1 &amp;lt;= max_year; // Double check this condition, I can't test it at the moment&lt;/P&gt;
&lt;P&gt;3) Group by the entire dimension list and sum the payments&lt;/P&gt;
&lt;P&gt;Final:&lt;/P&gt;
&lt;P&gt;Noconcatenate Load contract_id, contract_year, payment_year, sum(payment) as payment&lt;/P&gt;
&lt;P&gt;Resident Original&lt;/P&gt;
&lt;P&gt;Group by contract_id, contract_year, payment_year;&lt;/P&gt;
&lt;P&gt;4) Drop the tables we don't need anymore:&lt;/P&gt;
&lt;P&gt;Drop table Original;&lt;/P&gt;
&lt;P&gt;Drop Table NewTable;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 19:21:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Tricky-Scripting-Question/m-p/2502092#M103419</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2025-01-20T19:21:21Z</dc:date>
    </item>
  </channel>
</rss>

