<?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: Add a Calculated Column through Load Script in Connectivity &amp; Data Prep</title>
    <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448082#M13616</link>
    <description>&lt;P&gt;This is how to go about it.&lt;/P&gt;
&lt;P&gt;Left Join(Invoice.Details)&lt;BR /&gt;LOAD Invoice.Number as Invoice.Number ,&lt;BR /&gt;Sum(Item.Cost - Item.Sale.Price) as Item.Profit&lt;/P&gt;
&lt;P&gt;Resident Invoice.Details&lt;BR /&gt;Group By Invoice.Number;&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2024 18:54:33 GMT</pubDate>
    <dc:creator>BrunPierre</dc:creator>
    <dc:date>2024-05-02T18:54:33Z</dc:date>
    <item>
      <title>Add a Calculated Column through Load Script</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448077#M13615</link>
      <description>&lt;P&gt;I need to add a column to a table, based on data from within that table itself.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's use this example, Table Name [Invoice Details]:&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="34px"&gt;Invoice Number&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="34px"&gt;Item Cost&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="34px"&gt;Item Sale Price&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="34px"&gt;123456&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="34px"&gt;$5.00&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="34px"&gt;$10.00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="55px"&gt;987654&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="55px"&gt;$7.50&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="55px"&gt;
&lt;P&gt;$20.00&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;I need to add a new column to the [Invoice Details] table that is [Item Profit] that will be [Item Sale Price] - [Item Cost].&lt;/P&gt;
&lt;P&gt;Now, I know I could do this when I initially load the table, but in my example Item Cost and Item Sale Price are both pretty complex calculations to begin with, and I don't want to copy both of those expressions into yet another field to complete the [Item Profit] calculation. Said another way, if in the future, the [Item Sale Price] calculation changes, I would like that change to "cascade" to the [Item Profit] calculation without needing the developer to remember to copy his changes to both fields.&lt;/P&gt;
&lt;P&gt;So, how do I essentially LEFT JOIN a table to itself?&lt;/P&gt;
&lt;P&gt;Essentially, I think I need to do this:&lt;/P&gt;
&lt;P&gt;LEFT JOIN ([Invoice Details])&lt;BR /&gt;LOAD [Item Sale Price] - [Item Cost] as [Item Profit]&lt;BR /&gt;Resident [Invoice Details]&lt;/P&gt;
&lt;P&gt;But that obviously doesn't work out for me. What am I missing here?&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 18:16:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448077#M13615</guid>
      <dc:creator>jon-laudner</dc:creator>
      <dc:date>2024-05-02T18:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add a Calculated Column through Load Script</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448082#M13616</link>
      <description>&lt;P&gt;This is how to go about it.&lt;/P&gt;
&lt;P&gt;Left Join(Invoice.Details)&lt;BR /&gt;LOAD Invoice.Number as Invoice.Number ,&lt;BR /&gt;Sum(Item.Cost - Item.Sale.Price) as Item.Profit&lt;/P&gt;
&lt;P&gt;Resident Invoice.Details&lt;BR /&gt;Group By Invoice.Number;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 18:54:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448082#M13616</guid>
      <dc:creator>BrunPierre</dc:creator>
      <dc:date>2024-05-02T18:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add a Calculated Column through Load Script</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448087#M13617</link>
      <description>&lt;P&gt;In this case, there's no GROUP BY necessary, it's line-by-line. And when I try to LEFT JOIN a table to itself, I get an out of memory exception.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 19:08:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448087#M13617</guid>
      <dc:creator>jon-laudner</dc:creator>
      <dc:date>2024-05-02T19:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Add a Calculated Column through Load Script</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448092#M13618</link>
      <description>&lt;P&gt;That line of code groups the data by the Invoice.Number field. It ensures that the calculated profit is aggregated for each unique invoice number.&lt;/P&gt;
&lt;P&gt;Share the script to assist with debugging.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 19:24:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448092#M13618</guid>
      <dc:creator>BrunPierre</dc:creator>
      <dc:date>2024-05-02T19:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Add a Calculated Column through Load Script</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448096#M13619</link>
      <description>&lt;P&gt;That definitely worked. I tried but without my "Primary Key" or Invoice.Number in this example, and I think that's why I got the out of memory exception.&lt;/P&gt;
&lt;P&gt;In my case, it was a bit different than the original question, but this is the code that ended up working:&lt;/P&gt;
&lt;P&gt;LEFT JOIN ([Order Details])&lt;BR /&gt;LOAD OrderLineID as [OrderLineID], Only(Upper([Division ID])) as SA_DIVISIONID, Only(Upper([Is Invoiced])) as [SA_ISINVOICED]&lt;BR /&gt;RESIDENT [Order Details] &lt;BR /&gt;GROUP BY [OrderLineID]&lt;/P&gt;
&lt;P&gt;So I was successfully able to LEFT JOIN a table to itself. The reason I'm doing it this way is I have a Data Model app that has the entire load script, while this code is going in just one of the many UI apps to do some Section Access, and I didn't want to add these SA_ columns to the original Data Model.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2024 19:37:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Add-a-Calculated-Column-through-Load-Script/m-p/2448096#M13619</guid>
      <dc:creator>jon-laudner</dc:creator>
      <dc:date>2024-05-02T19:37:48Z</dc:date>
    </item>
  </channel>
</rss>

