<?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: Sum expression with AddMonths to a variable in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1976369#M80535</link>
    <description>&lt;P&gt;The issue appears to be that you're not telling Qlik that to actually calculate the AddMonths-function, it's being interpreted literally instead of executing.&lt;/P&gt;
&lt;P&gt;Try the following measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({&amp;lt;[date]= {'$(=AddMonths($(vLatestDate), -1))'}&amp;gt;} [amount]) &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Note the addition of "="-character to the start of the dollar expansion, to tell Qlik to calculate the dollar expansion and not simply do a string replace. Sometimes the end result of your date adjustment might not meet the format of your target field, but in this case it should be fine. But if you wanted to for example do a MonthYear-field selection based on your vLatestDate, you'd have to add a formatting function after the AddMonths, such as MonthName-function or whichever format the target field is in.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2022 13:42:52 GMT</pubDate>
    <dc:creator>oskartoivonen</dc:creator>
    <dc:date>2022-09-02T13:42:52Z</dc:date>
    <item>
      <title>Sum expression with AddMonths to a variable</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974646#M80395</link>
      <description>&lt;P&gt;I created a variable&amp;nbsp;&lt;EM&gt;vLatestDate &lt;/EM&gt;which is derived from the max month of the [date] column&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Denzyl_0-1661777856696.png" style="width: 161px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/87725i0B272B67457AF697/image-dimensions/161x149?v=v2" width="161" height="149" role="button" title="Denzyl_0-1661777856696.png" alt="Denzyl_0-1661777856696.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;vLatestDate&lt;/EM&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Max([date])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code gives me the sum of [amount] where [date] equals to &lt;EM&gt;vLatestDate:&lt;/EM&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({&amp;lt;[date]= {'$(vLatestDate)'}&amp;gt;} [amount])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;I am now trying to create a column that is a sum expression based on the [date] column matching the &lt;EM&gt;vLatestDate&lt;/EM&gt; variable minus one month.&lt;/P&gt;
&lt;P&gt;I have tried the following code but it does not work:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({&amp;lt;[date]= {'$(AddMonths(vLatestDate, -1))'}&amp;gt;} [amount]) &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Denzyl_0-1661844344523.png" style="width: 241px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/87813iD3A15B27CC3A2930/image-dimensions/241x35?v=v2" width="241" height="35" role="button" title="Denzyl_0-1661844344523.png" alt="Denzyl_0-1661844344523.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 08:24:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974646#M80395</guid>
      <dc:creator>Denzyl</dc:creator>
      <dc:date>2022-08-30T08:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sum expression with AddMonths to a variable</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974693#M80398</link>
      <description>&lt;P&gt;may be this instead&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({&amp;lt;[date]= {'AddMonths ($(vLatestDate), -1)'}&amp;gt;} [amount]) &lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 30 Aug 2022 09:25:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974693#M80398</guid>
      <dc:creator>brunobertels</dc:creator>
      <dc:date>2022-08-30T09:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sum expression with AddMonths to a variable</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974701#M80399</link>
      <description>&lt;P&gt;The sum of the measure is all 0.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Denzyl_0-1661851899490.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/87848iA3618D5674F72CC9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Denzyl_0-1661851899490.png" alt="Denzyl_0-1661851899490.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 09:32:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974701#M80399</guid>
      <dc:creator>Denzyl</dc:creator>
      <dc:date>2022-08-30T09:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sum expression with AddMonths to a variable</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974710#M80401</link>
      <description>&lt;P&gt;try this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;create a new field&lt;/P&gt;
&lt;P&gt;num(Date) as numDate in script;&lt;/P&gt;
&lt;P&gt;=Sum({$&amp;lt;numDate={'$(=num(Addmonths(Max(numDate),-1)))'}&amp;gt;}Sales)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the attached file&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 09:38:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1974710#M80401</guid>
      <dc:creator>SunilChauhan</dc:creator>
      <dc:date>2022-08-30T09:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sum expression with AddMonths to a variable</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1976369#M80535</link>
      <description>&lt;P&gt;The issue appears to be that you're not telling Qlik that to actually calculate the AddMonths-function, it's being interpreted literally instead of executing.&lt;/P&gt;
&lt;P&gt;Try the following measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({&amp;lt;[date]= {'$(=AddMonths($(vLatestDate), -1))'}&amp;gt;} [amount]) &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Note the addition of "="-character to the start of the dollar expansion, to tell Qlik to calculate the dollar expansion and not simply do a string replace. Sometimes the end result of your date adjustment might not meet the format of your target field, but in this case it should be fine. But if you wanted to for example do a MonthYear-field selection based on your vLatestDate, you'd have to add a formatting function after the AddMonths, such as MonthName-function or whichever format the target field is in.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 13:42:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-expression-with-AddMonths-to-a-variable/m-p/1976369#M80535</guid>
      <dc:creator>oskartoivonen</dc:creator>
      <dc:date>2022-09-02T13:42:52Z</dc:date>
    </item>
  </channel>
</rss>

