<?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: Date formatting and variable in SET expression, Moving Annual Total in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1755828#M58282</link>
    <description>&lt;P&gt;Excellent, glad it works for you.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2020 11:07:09 GMT</pubDate>
    <dc:creator>stevedark</dc:creator>
    <dc:date>2020-10-26T11:07:09Z</dc:date>
    <item>
      <title>Date formatting and variable in SET expression, Moving Annual Total</title>
      <link>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1754800#M58189</link>
      <description>&lt;P&gt;Hi Qlik friends, I have a problem creating a SET expression for Moving Annual Total. I´ve got fields Period, Amount, Year, Month:&lt;/P&gt;&lt;P&gt;Format of field Period is:&lt;/P&gt;&lt;P&gt;202009&lt;/P&gt;&lt;P&gt;202008&lt;/P&gt;&lt;P&gt;202007&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I also got a variable with the start date of max(Month). The variable is called&amp;nbsp;$(vMaxSelectedMonth_StartDate) and if you select Month = September, the result of this variable is '2020-09-01'.&lt;/P&gt;&lt;P&gt;Now I need the Moving Annual Total of Amount. This is the sum of Amount for Periods 201910 - 202009 if you select September 2020. But I also want separate expression for Moving Annual Total&amp;nbsp; previous Month, that are periods 201909 - 202008 if you select September 2020. Separate expression for&amp;nbsp; Month-2, Month-3 and so on until Month-12.&lt;/P&gt;&lt;P&gt;For the selected month this works fine:&lt;/P&gt;&lt;P&gt;Sum({&amp;lt;Period = {"&amp;gt;$(=Max(Period)-100)"}&amp;gt;} Amount)&lt;/P&gt;&lt;P&gt;but it doesn´t work for Month-1, Month-2 and so on...&lt;/P&gt;&lt;P&gt;I´m thinking I need to change the format of Period to 'YYYY-MM-DD' and compare to the variable&amp;nbsp;$(vMaxSelectedMonth_StartDate). Can this be done in a SET expression? What would that look like?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 21:08:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1754800#M58189</guid>
      <dc:creator>JohanLind1979</dc:creator>
      <dc:date>2021-12-20T21:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Date formatting and variable in SET expression, Moving Annual Total</title>
      <link>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1755467#M58251</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/110697"&gt;@JohanLind1979&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With set analysis and dates the formatting is really important. Having the period as a number makes things simpler, for sure.&lt;/P&gt;&lt;P&gt;You can format the content of the variable to match the period field like this:&lt;/P&gt;&lt;P&gt;=Date(Max(Month), 'YYYYMM')&lt;/P&gt;&lt;P&gt;That should then allow you to use it in the set analysis against the period.&lt;/P&gt;&lt;P&gt;If you need to take off a number of months though you have a problem that the numbers are not fully sequential (i.e. 202001 does not follow 202012). You can get around this by creating a field which is months since 1900, by doing this in your load script:&lt;/P&gt;&lt;P&gt;(Year(Date)*12)+Month(Date)) as MonthNo,&lt;/P&gt;&lt;P&gt;This gives you a numeric sequence of months, so to get the number of the month three before the latest you can do&amp;nbsp;&lt;STRONG&gt;max(MonthNo)-3&lt;/STRONG&gt;. This can simplify set analysis and prior period comparisons, but is not useful to show the user in any way shape or form.&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Fri, 23 Oct 2020 14:07:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1755467#M58251</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2020-10-23T14:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Date formatting and variable in SET expression, Moving Annual Total</title>
      <link>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1755822#M58280</link>
      <description>&lt;P&gt;That was really really smart! Love that solution, thank´s! One slight adjustment needed though, I think it should be&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(Year(Date)*12)+(Month(Date)) as MonthNo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Parenthesis missing in your post....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also I don´t think I need your formula =Date(Max(Month), 'YYYYMM') for the variable. Max(Period) is the same result in my case.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 11:00:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1755822#M58280</guid>
      <dc:creator>JohanLind1979</dc:creator>
      <dc:date>2020-10-26T11:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Date formatting and variable in SET expression, Moving Annual Total</title>
      <link>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1755828#M58282</link>
      <description>&lt;P&gt;Excellent, glad it works for you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2020 11:07:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Date-formatting-and-variable-in-SET-expression-Moving-Annual/m-p/1755828#M58282</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2020-10-26T11:07:09Z</dc:date>
    </item>
  </channel>
</rss>

