<?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: If condition is incorrect in script - problem adding x amount of months to a date in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50061#M607931</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;one possible solution using your sample data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="198359" alt="QlikCommunity_Thread_296952_Pic1.JPG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/198359_QlikCommunity_Thread_296952_Pic1.JPG" style="height: auto; width: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15227920775022833" jivemacro_uid="_15227920775022833"&gt;
&lt;P&gt;table1:&lt;/P&gt;
&lt;P&gt;LOAD Name,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date([Start Date]) as [Start Date],&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Money([Yearly Direct Labor]) as [Yearly Direct Labor],&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month(Date#(IterNo(),'M')) as Month,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; numMonths,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Money(If(IterNo()&amp;gt;=Month([Start Date]) and IterNo()&amp;lt;Month([Start Date])+numMonths,[Yearly Direct Labor]/numMonths,0)) as [Direct Labor]&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FROM [&lt;/SPAN&gt;&lt;A _jive_internal="true" data-containerid="-1" data-containertype="-1" data-objectid="320647" data-objecttype="13" href="https://community.qlik.com/servlet/JiveServlet/download/2061-296952-1463901-320647/Example.xlsx"&gt;https://community.qlik.com/servlet/JiveServlet/download/1463901-320647/Example.xlsx&lt;/A&gt;&lt;SPAN&gt;] (ooxml, embedded labels, table is Sheet1)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;While IterNo()&amp;lt;=12;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What result do you expect for Start Date / numMonths combinations that span multiple years?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Marco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Apr 2018 21:52:18 GMT</pubDate>
    <dc:creator>MarcoWedel</dc:creator>
    <dc:date>2018-04-03T21:52:18Z</dc:date>
    <item>
      <title>If condition is incorrect in script - problem adding x amount of months to a date</title>
      <link>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50058#M607928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Qlik Community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following script that divides a yearly labor cost evenly into months based on a starting date. The script works great as it assumes the yearly cost should be split from month([Start Date]) through the end of the year. In other words, monthly cost = yearlyCost / (13 - month([Start Date])). I have several cases where the length of the contract does not continue through the end of the year. There is another field in the data that is the length of the contract which can be used to solve this problem. Below is the code of the working script. I am using Qlik Sense in the cloud.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c#" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15227834916679823" jivemacro_uid="_15227834916679823"&gt;
&lt;P&gt;table1:&lt;/P&gt;
&lt;P&gt;LOAD Name,&lt;/P&gt;
&lt;P&gt;Date([Start Date]) as [Start Date],&lt;/P&gt;
&lt;P&gt;Money(yearlyCost) as [yearlyCost],&lt;/P&gt;
&lt;P&gt;Month(Date#(IterNo(),'M')) as Month,&lt;/P&gt;
&lt;P&gt;Money(If(IterNo()&amp;gt;=Month([Start Date]),[&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;yearlyCost&lt;/SPAN&gt;]/(13-Month([Start Date])),0)) as [Direct Labor]&lt;/P&gt;
&lt;P&gt;FROM mytable.xlsx (ooxml, embedded labels, table is Sheet1)&amp;nbsp; While IterNo()&amp;lt;=12;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have changed my if statement in line 6 to the following, which utilizes the field numMonths.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;Money(If(IterNo()&amp;gt;=Month([Start Date]) and '$(Month)' &amp;lt;= Month([StartDate]) + Month(Date#([numMonths], 'M')),[2019 NTC Direct Labor]/numMonths,0)) as [Direct Labor]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;This is what the output should look like below except for in the case of name = b, the numMonths = 2 so only June and July should split the total cost at $2500 each. Same with name = c, spread out over 4 months (May, June, July, August).&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image" src="https://community.qlik.com/legacyfs/online/198342_QlikCommunity_Thread_296776_Pic1.JPG" /&gt;&lt;/P&gt;&lt;P&gt;Any help on getting this working correctly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Zach&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2018 19:30:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50058#M607928</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-03T19:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: If condition is incorrect in script - problem adding x amount of months to a date</title>
      <link>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50059#M607929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;pl attach sample excel with expected output&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2018 19:41:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50059#M607929</guid>
      <dc:creator>sasiparupudi1</dc:creator>
      <dc:date>2018-04-03T19:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: If condition is incorrect in script - problem adding x amount of months to a date</title>
      <link>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50060#M607930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have updated my question. Also, this is the link to the original question, maybe it provides more details.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/thread/296776"&gt;Load in for each loop that iterates over months&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Zach&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2018 20:36:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50060#M607930</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-03T20:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: If condition is incorrect in script - problem adding x amount of months to a date</title>
      <link>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50061#M607931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;one possible solution using your sample data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="198359" alt="QlikCommunity_Thread_296952_Pic1.JPG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/198359_QlikCommunity_Thread_296952_Pic1.JPG" style="height: auto; width: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15227920775022833" jivemacro_uid="_15227920775022833"&gt;
&lt;P&gt;table1:&lt;/P&gt;
&lt;P&gt;LOAD Name,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date([Start Date]) as [Start Date],&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Money([Yearly Direct Labor]) as [Yearly Direct Labor],&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Month(Date#(IterNo(),'M')) as Month,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; numMonths,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Money(If(IterNo()&amp;gt;=Month([Start Date]) and IterNo()&amp;lt;Month([Start Date])+numMonths,[Yearly Direct Labor]/numMonths,0)) as [Direct Labor]&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FROM [&lt;/SPAN&gt;&lt;A _jive_internal="true" data-containerid="-1" data-containertype="-1" data-objectid="320647" data-objecttype="13" href="https://community.qlik.com/servlet/JiveServlet/download/2061-296952-1463901-320647/Example.xlsx"&gt;https://community.qlik.com/servlet/JiveServlet/download/1463901-320647/Example.xlsx&lt;/A&gt;&lt;SPAN&gt;] (ooxml, embedded labels, table is Sheet1)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;While IterNo()&amp;lt;=12;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What result do you expect for Start Date / numMonths combinations that span multiple years?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Marco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2018 21:52:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-condition-is-incorrect-in-script-problem-adding-x-amount-of/m-p/50061#M607931</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2018-04-03T21:52:18Z</dc:date>
    </item>
  </channel>
</rss>

