<?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: Limit KPI by time range in set analysis using variables in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1857803#M70813</link>
    <description>&lt;P&gt;Hi, there are some things to comment:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;- GetFieldSelections can return many different values if the user selects more than one month, that can break the logic.&lt;/LI&gt;
&lt;LI&gt;Confirm that the original&amp;nbsp;MonthYear field is a number, you can check adding a filter or this field as dimension in a table, if it's left aligned is a text, if it's right-aligned is a number (internally a date is a number)&lt;/LI&gt;
&lt;LI&gt;- I think that Qlik is using vEndMonth and vStartMonth as numbers, and the space is breaking that number&lt;/LI&gt;
&lt;LI&gt;- If the space is not breaking the number the logic would work either as may-2021 wil be lower than oct-2019 because 052021 is a number lower than 102019.&lt;/LI&gt;
&lt;LI&gt;Format issues are very common when filtering by dates&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;To solve this points you can use&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;avoid most of this comments I usually have a date in a number format to avoid format issues, from the&amp;nbsp;MonthYear field you can create the date as number as:&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="markup"&gt;Num(MakeDate(Year(MonthYear),Month(MonthYear))) as NumDate&lt;/LI-CODE&gt;
&lt;P&gt;Or if you want consecutive numbers&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;=(Year(MonthYear)*12)+Month(MonthYear) as NumYearMonth&lt;/LI-CODE&gt;
&lt;UL&gt;
&lt;LI&gt;Use Max and Min to retrieve the lower and higher month&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="markup"&gt;vStartMonth= Min(NumDate);  Min(NumYearMonth)&lt;/LI-CODE&gt;
&lt;P&gt;So the final expression can be&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({$&amp;lt; NumYearMonth= {"&amp;lt;$(=vEndMonth)&amp;gt;=$(=vStartMonth)"}&amp;gt;} [turnover])&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 10 Nov 2021 15:57:11 GMT</pubDate>
    <dc:creator>rubenmarin</dc:creator>
    <dc:date>2021-11-10T15:57:11Z</dc:date>
    <item>
      <title>Limit KPI by time range in set analysis using variables</title>
      <link>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1857673#M70799</link>
      <description>&lt;DIV class="s-prose js-post-body"&gt;
&lt;P&gt;I want to be able to limit a KPI, let's say turnover, to a specific time range which I chose by setting two variables: the lower bound and the upper bound.&lt;/P&gt;
&lt;P&gt;I have created two tables, which I derive from the calendar-table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;month_start:
LOAD MonthYear as MonthStart
RESIDENT Calendar;

month_end:
LOAD MonthYear as MonthEnd
RESIDENT Calendar;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I create two filters, one for MonthStart and one for MonthEnd.&lt;/P&gt;
&lt;P&gt;I set two variables. I know that&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;GetFieldSelections()&lt;/CODE&gt;returns a string so I convert it back to a date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;=date#(GetFieldSelections(MonthEnd), 'MM YYYY')

=date#(GetFieldSelections(MonthStart), 'MM YYYY')
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally I use this expression to calculate the KPI:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;SUM({$&amp;lt; MonthYear = {"&amp;lt;$(=vEndMonth)&amp;gt;=$(=vStartMonth)"}&amp;gt;} [turnover])
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it doesn't work. The measure returns 0,00€ (the data is definitly there though).&lt;/P&gt;
&lt;P&gt;What am I doing wrong? What am I missing?&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV class="mt24 mb12"&gt;
&lt;DIV class="post-taglist d-flex gs4 gsy fd-column"&gt;
&lt;DIV class="d-flex ps-relative"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 Nov 2021 13:40:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1857673#M70799</guid>
      <dc:creator>Kellerassel</dc:creator>
      <dc:date>2021-11-10T13:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Limit KPI by time range in set analysis using variables</title>
      <link>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1857803#M70813</link>
      <description>&lt;P&gt;Hi, there are some things to comment:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;- GetFieldSelections can return many different values if the user selects more than one month, that can break the logic.&lt;/LI&gt;
&lt;LI&gt;Confirm that the original&amp;nbsp;MonthYear field is a number, you can check adding a filter or this field as dimension in a table, if it's left aligned is a text, if it's right-aligned is a number (internally a date is a number)&lt;/LI&gt;
&lt;LI&gt;- I think that Qlik is using vEndMonth and vStartMonth as numbers, and the space is breaking that number&lt;/LI&gt;
&lt;LI&gt;- If the space is not breaking the number the logic would work either as may-2021 wil be lower than oct-2019 because 052021 is a number lower than 102019.&lt;/LI&gt;
&lt;LI&gt;Format issues are very common when filtering by dates&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;To solve this points you can use&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;avoid most of this comments I usually have a date in a number format to avoid format issues, from the&amp;nbsp;MonthYear field you can create the date as number as:&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="markup"&gt;Num(MakeDate(Year(MonthYear),Month(MonthYear))) as NumDate&lt;/LI-CODE&gt;
&lt;P&gt;Or if you want consecutive numbers&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;=(Year(MonthYear)*12)+Month(MonthYear) as NumYearMonth&lt;/LI-CODE&gt;
&lt;UL&gt;
&lt;LI&gt;Use Max and Min to retrieve the lower and higher month&lt;/LI&gt;
&lt;/UL&gt;
&lt;LI-CODE lang="markup"&gt;vStartMonth= Min(NumDate);  Min(NumYearMonth)&lt;/LI-CODE&gt;
&lt;P&gt;So the final expression can be&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({$&amp;lt; NumYearMonth= {"&amp;lt;$(=vEndMonth)&amp;gt;=$(=vStartMonth)"}&amp;gt;} [turnover])&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 10 Nov 2021 15:57:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1857803#M70813</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2021-11-10T15:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Limit KPI by time range in set analysis using variables</title>
      <link>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1858044#M70829</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;BR /&gt;&lt;BR /&gt;Let me first address your comments where necessary:&lt;BR /&gt;&lt;BR /&gt;1. I have the "Always&amp;nbsp; one selected value"- field setting activated. So the filters for `MonthYear` always have one, and only one, value selected.&lt;/P&gt;
&lt;P&gt;2. The MonthYear-field is created as `monthname(%date) as MonthYear` which allegedly returns a dual representation with a numeric value. It has tags `$numeric $integer $timestamp $date`&lt;BR /&gt;&lt;BR /&gt;I'm not sure how to go about following your suggestions.&lt;BR /&gt;&lt;BR /&gt;1. I can create a calendar-field&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Num(MakeDate(Year(MonthYear),Month(MonthYear))) as NumDate&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. But the user choses the Start-Month and End-Month in two separate filter panes. For these I need a readable date format so people know what they are selecting. A number doesn't work here.&lt;BR /&gt;&lt;BR /&gt;3. So&amp;nbsp;vStartMonth and vEndMonth should be numeric, but they need to be selected via a date formatted field. Therefore I changed the variable definition to:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;= Num#(date#(GetFieldSelections(MonthStart), 'MM YYYY'))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;So whatever the format in the filter pane, the variable definitely contains a number. But it still doesn't work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;As a note: I can't apply `date`, `num` or `monthname` around `date#(GetFieldSelections(MonthStart), 'MM YYYY'))`. Wonder why?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 09:08:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1858044#M70829</guid>
      <dc:creator>Kellerassel</dc:creator>
      <dc:date>2021-11-11T09:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Limit KPI by time range in set analysis using variables</title>
      <link>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1858228#M70849</link>
      <description>&lt;P&gt;Hi, the NumDate field would be an additional field in the Calendar table, then an expression like this should work:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SUM({$&amp;lt; NumDate= {"&amp;lt;$(=Num(Date#('$(vEndMonth)','MM YYYY')))&amp;gt;=$(=Num(Date#('$(vStartMonth)','MM YYYY')))"}&amp;gt;} [turnover])&lt;/LI-CODE&gt;
&lt;P&gt;But your last point can affect here, you should be able to use date or num around Date#, can you upload a dumb sample to check?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 14:24:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Limit-KPI-by-time-range-in-set-analysis-using-variables/m-p/1858228#M70849</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2021-11-11T14:24:52Z</dc:date>
    </item>
  </channel>
</rss>

