<?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: Duplicate lines doubling amount in script due to left join in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Duplicate-lines-doubling-amount-in-script-due-to-left-join/m-p/2511796#M105126</link>
    <description>&lt;P&gt;I wouldn't tend to join these tables else to map them. It has no risks to change the number of records and the mapped value could be immediate evaluated instead needing an afterward load-step. Further mappings could be nested in various ways, for example within their third parameter might the next mapping&amp;nbsp;be called.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Mar 2025 07:37:05 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2025-03-27T07:37:05Z</dc:date>
    <item>
      <title>Duplicate lines doubling amount in script due to left join</title>
      <link>https://community.qlik.com/t5/App-Development/Duplicate-lines-doubling-amount-in-script-due-to-left-join/m-p/2511711#M105108</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I'm having a slight issue with the output my script is producing and hopefully, someone has an idea as to how to tackle this issue.&lt;/P&gt;&lt;P&gt;The actual script is more complex than the sample I'm about to provide, but the logic behind it remains the same.&lt;/P&gt;&lt;P&gt;I have a business logic script that starts off with Table A. This table is the basis and contains one field (invoice amount) that needs to be overridden with the correct values- hence the creation of this BL.&lt;/P&gt;&lt;P&gt;To quickly visualize it for everyone, the entries for table A end up looking like this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Requisition Doc&lt;/STRONG&gt;&amp;nbsp;|&amp;nbsp;&lt;STRONG&gt;Requisition level&amp;nbsp;&lt;/STRONG&gt;|&amp;nbsp;&lt;STRONG&gt;Category&lt;/STRONG&gt;&amp;nbsp;|&amp;nbsp;&lt;STRONG&gt;Invoice Amt |&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;RefID&lt;/STRONG&gt;&amp;nbsp;|&amp;nbsp;&lt;STRONG&gt;RefLev&lt;/STRONG&gt;&amp;nbsp;|&amp;nbsp;&lt;STRONG&gt;OrderID |&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;OrderLev&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;4589762&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; E&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500.05&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75635&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2075624&amp;nbsp; &amp;nbsp; 1000&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Invoice Amt will be renamed to [Invoice Amt_Past] to easily differentiate it from the new Invoice Amt that will be generated as the script progresses.&lt;/P&gt;&lt;P&gt;The initial primary keys - to allow the succeeding tables to link back to Table A - are also generated here.&amp;nbsp;&lt;BR /&gt;[Requision Doc] &amp;amp; '/' &amp;amp; [Requisition Item] as %RecDoc%RecItem&lt;/P&gt;&lt;P&gt;[RefID] &amp;amp; '/' &amp;amp; [RefLev] as %RefID%RefItem&lt;/P&gt;&lt;P&gt;[OrderID] &amp;amp; '/' &amp;amp; [OrderLev] as %OrderID%OrderLev&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new invoice amount will come from two different tables (Table B &amp;amp; Table C), depending on the category it has been assigned in Table A. The new invoice amount for Category 'E' documents will be pulled from Table B, and the new invoice amount for documents with Category 'S' will be taken from Table C.&lt;BR /&gt;&lt;BR /&gt;This wouldn't be an issue, but the category field is currently not being generated in our base table, which makes it unavailable to use. So we had to work around this by saying "if there's an amount in Table B for this document, take this, otherwise, take the amount in Table C".&lt;/P&gt;&lt;P&gt;Which worked fine up until a few days ago, which we'll get to in a little bit.&lt;/P&gt;&lt;P&gt;For table B, the entries will look like this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RefID&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;RefLev&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Amount_Ref&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;75635&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 453.12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We create the key&amp;nbsp;%RefID%RefItem, grab the new amount (Amount_Ref), and left join it to Table A.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Getting to Table C requires an additional table in between (Table C5), because we will need to link Table C to Table C5 in order to get it connected back to Table A.&lt;BR /&gt;So we start off with &lt;STRONG&gt;Table C5&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;OrderID&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;OrderLev&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;EventID&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;EventLev&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2075624&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;888456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 00100&lt;/P&gt;&lt;P&gt;2075624&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;888456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 00200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following keys are then created: %OrderID%OrderLev and %EventID%EventLev&lt;/P&gt;&lt;P&gt;Table C:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EventID&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;EventLev&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Amount_Event&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;888456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;888456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;00200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 453.12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key&amp;nbsp;%EventID%EventLev is created and left joined to Table C5.&lt;/P&gt;&lt;P&gt;A third table is then generated, resident loading [%OrderID%OrderLev] and Amount_Event from C5, which we then left join back to Table A.&lt;BR /&gt;&lt;BR /&gt;But because of the two lines that exist in Table C5, when the last left join happens, my&amp;nbsp;Amount_Ref cost DUPLICATES. Doubling when it really shouldn't. Due to the table now looking like this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Requisition Doc&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&lt;STRONG&gt;Requisition level&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;RefID&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;RefLev&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;OrderID&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;OrderLev&lt;/STRONG&gt;&amp;nbsp; |&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Amount_Final&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;4589762&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75635&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2075624&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 453.12&lt;/P&gt;&lt;P&gt;4589762&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75635&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2075624&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 453.12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rather than the total just being 453.12, it's now 906.24. The left join is necessary because at the end of the script, all of the amounts gets consolidated into 1 table, generating just a single field: &lt;FONT color="#FF6600"&gt;Amount_Final&lt;/FONT&gt; that we then reference in the data model later on for master measurers and visualizations.&lt;BR /&gt;&lt;BR /&gt;I've sent a request in to get that category added to the raw script, but until we can get that included, I unfortunately need to work around the system. Does anyone have any suggestions as to how I can eradicate the duplicate line? Loading distinct and even removing the SUM and aggregations inside the code itself did not work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 15:14:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Duplicate-lines-doubling-amount-in-script-due-to-left-join/m-p/2511711#M105108</guid>
      <dc:creator>bvendeza</dc:creator>
      <dc:date>2025-03-26T15:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate lines doubling amount in script due to left join</title>
      <link>https://community.qlik.com/t5/App-Development/Duplicate-lines-doubling-amount-in-script-due-to-left-join/m-p/2511778#M105122</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/154772"&gt;@bvendeza&lt;/a&gt;&amp;nbsp;Mathematically You can take Average over sum so even if multiple records are there you will get the right sum since your amount value is same for multiple entries.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 05:44:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Duplicate-lines-doubling-amount-in-script-due-to-left-join/m-p/2511778#M105122</guid>
      <dc:creator>Bhushan_Mahajan</dc:creator>
      <dc:date>2025-03-27T05:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate lines doubling amount in script due to left join</title>
      <link>https://community.qlik.com/t5/App-Development/Duplicate-lines-doubling-amount-in-script-due-to-left-join/m-p/2511796#M105126</link>
      <description>&lt;P&gt;I wouldn't tend to join these tables else to map them. It has no risks to change the number of records and the mapped value could be immediate evaluated instead needing an afterward load-step. Further mappings could be nested in various ways, for example within their third parameter might the next mapping&amp;nbsp;be called.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 07:37:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Duplicate-lines-doubling-amount-in-script-due-to-left-join/m-p/2511796#M105126</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2025-03-27T07:37:05Z</dc:date>
    </item>
  </channel>
</rss>

