<?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: Calculate a Field in script based on other calculated Fields in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1677670#M738994</link>
    <description>&lt;P&gt;It depends....in most cases, I would say that it would be better to do it in the script... but this is not always 100% true. If your data model gets really complicated and huge, it might be better to do it on the front end.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Feb 2020 16:42:03 GMT</pubDate>
    <dc:creator>sunny_talwar</dc:creator>
    <dc:date>2020-02-20T16:42:03Z</dc:date>
    <item>
      <title>Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587089#M738981</link>
      <description>&lt;P&gt;Hi&amp;nbsp; - I need to Calculate a Field based on previous fields I calculated in the script&lt;/P&gt;&lt;P&gt;I basically need to calculate&amp;nbsp;[Net Available Stock]&amp;nbsp; based on [Stock IN], [Stock] and [Demand requested ] Calculated previously in the script.&lt;/P&gt;&lt;P&gt;Please see code sample bellow. if someone could help would be great. Many thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;BR /&gt;Metrics:&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;DATA,&lt;BR /&gt;QTY,&lt;BR /&gt;DateKey as Week,&lt;BR /&gt;[Weekly Avarage],&lt;BR /&gt;Period&lt;BR /&gt;Resident MasterData;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//// Calculate supply In ////&lt;/P&gt;&lt;P&gt;Left Join(Metrics)&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;sum(QTY) as [Supply In]&lt;BR /&gt;Resident Metrics&lt;BR /&gt;Where DATA='SI'&lt;BR /&gt;Group by SuperKeyM;&lt;/P&gt;&lt;P&gt;////Calculate Stock ////&lt;/P&gt;&lt;P&gt;Left Join(Metrics)&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;sum(QTY) as [Stock]&lt;BR /&gt;Resident Metrics&lt;BR /&gt;Where DATA='ST'&lt;BR /&gt;Group by SuperKeyM ;&lt;/P&gt;&lt;P&gt;//// Calculate Demand past////&lt;BR /&gt;Left Join(Metrics)&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;sum(QTY) as [Demand Requested1]&lt;/P&gt;&lt;P&gt;Resident Metrics&lt;BR /&gt;Where Period&amp;lt;&amp;gt;'Future' and DATA='TD'&lt;BR /&gt;Group by SuperKeyM;&lt;/P&gt;&lt;P&gt;//// Calculate Demand Future////&lt;/P&gt;&lt;P&gt;Left Join(Metrics)&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;sum(QTY) as [Demand Requestedcalc2]&lt;/P&gt;&lt;P&gt;Resident Metrics&lt;BR /&gt;Where Period='Future' and DATA='TD'&lt;BR /&gt;Group by SuperKeyM;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/// Calculate Compare Demand With Avarage////&lt;/P&gt;&lt;P&gt;Left Join(Metrics)&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;If([Demand Requestedcalc2]&amp;gt;[Weekly Avarage],[Demand Requestedcalc2],[Weekly Avarage]) as [Demand Requested2]&lt;BR /&gt;Resident Metrics&lt;BR /&gt;Where Period='Future';&lt;/P&gt;&lt;P&gt;///////////////////////////////////////Doesn't work from here //////////////////////////////////////////////////////////&lt;/P&gt;&lt;P&gt;/// Calculate Total Demand requested]&lt;/P&gt;&lt;P&gt;Left Join(Metrics)&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;[Demand Requested1] + [Demand Requested2] as [Demand requested]&lt;BR /&gt;Resident Metrics;&lt;/P&gt;&lt;P&gt;/////Calculate Net Available Stock /////&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;BR /&gt;MetricsFinal:&lt;BR /&gt;Load&lt;BR /&gt;SuperKeyM,&lt;BR /&gt;[Supply In],&lt;BR /&gt;[Stock],&lt;BR /&gt;Week,&lt;BR /&gt;[Demand requested],&lt;BR /&gt;If(Week='W-13',(([Stock]+ [Supply In]) - ([Demand requested])), (((Peek([Net Available Stock])) +[Supply In])- ([Demand requested]))) as [Net Available Stock]&lt;BR /&gt;Resident Metrics;&lt;BR /&gt;Drop Table Metrics;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587089#M738981</guid>
      <dc:creator>Pestaninha</dc:creator>
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587113#M738982</link>
      <description>&lt;P&gt;What issue are you running into when you run your script? Does it errors out?&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 11:52:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587113#M738982</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-05-31T11:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587123#M738983</link>
      <description>&lt;P&gt;Hi Sunny - it does&amp;nbsp; load the fields&amp;nbsp;[Demand requested] and [Net Available Stock]&amp;nbsp; but doesn't&amp;nbsp; return any value&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 12:08:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587123#M738983</guid>
      <dc:creator>Pestaninha</dc:creator>
      <dc:date>2019-05-31T12:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587134#M738984</link>
      <description>&lt;P&gt;Would you be able to provide sample data to see what might be the reason....&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 12:31:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587134#M738984</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-05-31T12:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587143#M738985</link>
      <description>&lt;P&gt;Sample attached&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 12:52:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587143#M738985</guid>
      <dc:creator>Pestaninha</dc:creator>
      <dc:date>2019-05-31T12:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587146#M738986</link>
      <description>&lt;P&gt;Is this the output you are getting? or is this sample data? It seems that Net Available Stock is already a field which is why it might be the output I feel... also where is Week field? Is DateKey = Week?&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 13:00:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587146#M738986</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-05-31T13:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587148#M738987</link>
      <description>&lt;P&gt;Hi Sunny, the first Table is a sample of the data, the second table is what i am getting with my script, also what i want to achieve but with correct values. Demand requested is returning all 0. If I Load fields Demand requested1 and Demand requested2&amp;nbsp; they return the correct values, but&amp;nbsp;Demand Requested1 +&amp;nbsp;Demand Requested1 = Demand requested&amp;nbsp; does not work&lt;/P&gt;&lt;P&gt;Yes, DateKey = Week&lt;/P&gt;&lt;P&gt;Many Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 13:09:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587148#M738987</guid>
      <dc:creator>Pestaninha</dc:creator>
      <dc:date>2019-05-31T13:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587156#M738988</link>
      <description>&lt;P&gt;sorry, I missed the tabs on the attached Excel.... checking it now&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 13:31:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587156#M738988</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-05-31T13:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587171#M738989</link>
      <description>&lt;P&gt;Not 100% sure on what output you are looking to get, but does this look like what you want?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 507px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/13022iB9ED7D40D6D2FC80/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script used&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Metrics:
LOAD SuperKeyM, 
     DateKey as Week, 
     Period, 
     DATA, 
     QTY, 
     [Weekly Avarage]
FROM
[..\..\Downloads\Data Sample.xlsx]
(ooxml, embedded labels, table is Data);

//// Calculate supply In ////

Left Join(Metrics)
LOAD SuperKeyM,
	 Sum(QTY) as [Supply In]
Resident Metrics
Where DATA = 'SI'
Group by SuperKeyM;

////Calculate Stock ////

Left Join(Metrics)
LOAD SuperKeyM,
	 Sum(QTY) as [Stock]
Resident Metrics
Where DATA = 'ST'
Group by SuperKeyM;

//// Calculate Demand past////
Left Join(Metrics)
LOAD SuperKeyM,
	 Sum(QTY) as [Demand Requested1]
Resident Metrics
Where Period &amp;lt;&amp;gt; 'Future' and DATA = 'TD'
Group by SuperKeyM;

//// Calculate Demand Future////

Left Join(Metrics)
LOAD SuperKeyM,
	 Sum(QTY) as [Demand Requestedcalc2]
Resident Metrics
Where Period = 'Future' and DATA = 'TD'
Group by SuperKeyM;

///Calculate Compare Demand With Avarage, Calculate Total Demand requested, &amp;amp; Calculate Net Available Stock /////

tmpMetrics:
LOAD SuperKeyM,
	 [Supply In],
	 [Stock],
	 Week,
	 RangeSum([Demand Requested1], If([Demand Requestedcalc2]&amp;gt;[Weekly Avarage],[Demand Requestedcalc2],[Weekly Avarage])) as [Demand requested]
Resident Metrics;

MetricsFinal:
LOAD *,
	 If(Week = 'W-13', RangeSum([Stock], [Supply In], -[Demand requested]), RangeSum(Peek('Net Available Stock'), [Supply In], -[Demand requested])) as [Net Available Stock]
Resident tmpMetrics
Order By SuperKeyM, Week;

DROP Tables Metrics, tmpMetrics;&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 31 May 2019 13:54:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587171#M738989</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-05-31T13:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587184#M738990</link>
      <description>&lt;P&gt;Very much Sunny, thanks a million &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 14:29:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1587184#M738990</guid>
      <dc:creator>Pestaninha</dc:creator>
      <dc:date>2019-05-31T14:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1588174#M738991</link>
      <description>&lt;P&gt;Hi Sunny -&amp;nbsp; I still have an issue with this, the table is duplicating values, I need a value by SuperKeyM otherwise calculations are incorrect. Any ides how I do this?&lt;/P&gt;&lt;P&gt;Many Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 13:18:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1588174#M738991</guid>
      <dc:creator>Pestaninha</dc:creator>
      <dc:date>2019-06-04T13:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1588290#M738992</link>
      <description>&lt;P&gt;Would you be able to share an example?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 16:45:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1588290#M738992</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-06-04T16:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1677659#M738993</link>
      <description>&lt;P&gt;Hi Sunny,&lt;/P&gt;&lt;P&gt;I have a similar case want to know which one would be best solution. Calculating the field again by doing a resident load or calculating it while creating a chart.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 16:21:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1677659#M738993</guid>
      <dc:creator>qliktowin</dc:creator>
      <dc:date>2020-02-20T16:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Field in script based on other calculated Fields</title>
      <link>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1677670#M738994</link>
      <description>&lt;P&gt;It depends....in most cases, I would say that it would be better to do it in the script... but this is not always 100% true. If your data model gets really complicated and huge, it might be better to do it on the front end.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2020 16:42:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Calculate-a-Field-in-script-based-on-other-calculated-Fields/m-p/1677670#M738994</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2020-02-20T16:42:03Z</dc:date>
    </item>
  </channel>
</rss>

