<?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: Using variables inside expressions in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1662418#M49744</link>
    <description>&lt;P&gt;First of all, in set analysis syntax you can only use field names on the left side of the = operator.&lt;/P&gt;&lt;P&gt;The statement let NewYear = IF (Today () &amp;lt;Date (YearStart (Today ()) + 15), 1, 0); will give the variable NewYear either the value 1 when the real world date is between januari 1st and 15th, the rest of the year the variable NewYear will have the value 0.&amp;nbsp; Count( {&amp;lt; 1 = 1 &amp;gt;} something) will do nothing because the left 1 is not the name of a field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;This mean, i need to count offers from last year when we are in 1-15 of january period, and get data from current year in the rest of cases.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Do you mean when we (the world) are in 1-15 januari or when the offers have an offer date between 1 and 15 januari?&lt;/P&gt;&lt;P&gt;If the latter then you should create a new field in the load script to flag the order records which have an orderdate between 1 and 15 januari:&lt;/P&gt;&lt;P&gt;Orders:&lt;BR /&gt;LOAD OfferId, OFFER_DATE, ..., Other fields, ..., &lt;STRONG&gt;If( DayNumberOfYear(OFFER_DATE) &amp;lt;= 15, 1, 0) as _FlagOfferDateJan1_15&lt;BR /&gt;&lt;/STRONG&gt;FROM ...source...&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;You can then use that flag field in the set analysis expression:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;count({$&amp;lt;[OFFER_DATE.autoCalendar.IsLastYear] = {1}, _FlagOfferDateJan1_15 = {1}&amp;gt;}&amp;nbsp;&amp;nbsp;+&amp;nbsp;{$&amp;lt; [OFFER_DATE.autoCalendar.IsCurrentYear] = {1}, _FlagOfferDateJan1_15 = {0}&amp;gt;} OFFER_ID)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2020 12:45:12 GMT</pubDate>
    <dc:creator>Gysbert_Wassenaar</dc:creator>
    <dc:date>2020-01-03T12:45:12Z</dc:date>
    <item>
      <title>Using variables inside expressions</title>
      <link>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1662407#M49741</link>
      <description>&lt;P&gt;Hello to everyone,&lt;/P&gt;&lt;P&gt;This is my first question in this forum, so thank you in advance to all who try to help me ... and sorry about my english, is not good as i'd like &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm starting to work on qlik sense and i'm a bit confusing (well a lot really) about "set analysis" syntax&lt;/P&gt;&lt;P&gt;I created the following variable with an expression:&lt;BR /&gt;&lt;STRONG&gt;let NewYear = IF (Today () &amp;lt;Date (YearStart (Today ()) + 15), 1, 0);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;It's working ok, i want to get 1 value when date is between january-1 and january-15 and 0 value in the rest of cases.&lt;/P&gt;&lt;P&gt;I need to use NewYear within an expression like this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;count({$&amp;lt;[OFFER_DATE.autoCalendar.IsLastYear] = {1}, $(NewYear) = {1}&amp;gt;}&amp;nbsp;&amp;nbsp;+&amp;nbsp;{$&amp;lt; [OFFER_DATE.autoCalendar.IsCurrentYear] = {1}, $(NewYear) = {0}&amp;gt;} OFFER_ID)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This mean, i need to count offers from last year when we are in 1-15 of january period, and get data from current year in the rest of cases.&lt;/P&gt;&lt;P&gt;As you can imagine, this is not working... i have spent a lot of hours searching similar problems within forums and trying different options but without&amp;nbsp;success. What am i doing wrong, or&amp;nbsp; isn't it possible?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 21:38:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1662407#M49741</guid>
      <dc:creator>Gonzalo</dc:creator>
      <dc:date>2021-12-20T21:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using variables inside expressions</title>
      <link>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1662412#M49743</link>
      <description>&lt;P&gt;Create field in script to get that done is the first option (Recommended*)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IF (Today () &amp;lt;Date (YearStart (Today ()) + 15), 1, 0) as NewYear&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;And expression you can use flag&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;count({$&amp;lt;[OFFER_DATE.autoCalendar.IsLastYear] = {1}, NewYear = {1}&amp;gt;} + {$&amp;lt; [OFFER_DATE.autoCalendar.IsCurrentYear] = {1}, NewYear = {0}&amp;gt;} OFFER_ID)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Or, If you like with in measure, Perhaps try&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;count({$&amp;lt;[OFFER_DATE.autoCalendar.IsLastYear] = {1}, Date = {"=IF (Today () &amp;lt;Date (YearStart (Today ()) + 15)"}&amp;gt;} + {$&amp;lt; [OFFER_DATE.autoCalendar.IsCurrentYear] = {1}, Date -= {"=IF (Today () &amp;lt;Date (YearStart (Today ()) + 15)"}&amp;gt;} OFFER_ID)&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 12:35:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1662412#M49743</guid>
      <dc:creator>Anil_Babu_Samineni</dc:creator>
      <dc:date>2020-01-03T12:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using variables inside expressions</title>
      <link>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1662418#M49744</link>
      <description>&lt;P&gt;First of all, in set analysis syntax you can only use field names on the left side of the = operator.&lt;/P&gt;&lt;P&gt;The statement let NewYear = IF (Today () &amp;lt;Date (YearStart (Today ()) + 15), 1, 0); will give the variable NewYear either the value 1 when the real world date is between januari 1st and 15th, the rest of the year the variable NewYear will have the value 0.&amp;nbsp; Count( {&amp;lt; 1 = 1 &amp;gt;} something) will do nothing because the left 1 is not the name of a field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;This mean, i need to count offers from last year when we are in 1-15 of january period, and get data from current year in the rest of cases.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Do you mean when we (the world) are in 1-15 januari or when the offers have an offer date between 1 and 15 januari?&lt;/P&gt;&lt;P&gt;If the latter then you should create a new field in the load script to flag the order records which have an orderdate between 1 and 15 januari:&lt;/P&gt;&lt;P&gt;Orders:&lt;BR /&gt;LOAD OfferId, OFFER_DATE, ..., Other fields, ..., &lt;STRONG&gt;If( DayNumberOfYear(OFFER_DATE) &amp;lt;= 15, 1, 0) as _FlagOfferDateJan1_15&lt;BR /&gt;&lt;/STRONG&gt;FROM ...source...&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;You can then use that flag field in the set analysis expression:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;count({$&amp;lt;[OFFER_DATE.autoCalendar.IsLastYear] = {1}, _FlagOfferDateJan1_15 = {1}&amp;gt;}&amp;nbsp;&amp;nbsp;+&amp;nbsp;{$&amp;lt; [OFFER_DATE.autoCalendar.IsCurrentYear] = {1}, _FlagOfferDateJan1_15 = {0}&amp;gt;} OFFER_ID)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 12:45:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1662418#M49744</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2020-01-03T12:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using variables inside expressions</title>
      <link>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1663946#M49937</link>
      <description>&lt;P&gt;ok, only fields can be used on left side of the = operator... understood &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I meant when the world is between 1st and 15th of january, not the offer date.&lt;/P&gt;&lt;P&gt;I've created a new field containg the value calculated, as&amp;nbsp;Anil_Babu_Samineni said&lt;/P&gt;&lt;P&gt;IF (Today () &amp;lt;Date (YearStart (Today ()) + 15), 1, 0) as NewYear&lt;/P&gt;&lt;P&gt;And now expressions are ok and working as expected&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 08:59:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-variables-inside-expressions/m-p/1663946#M49937</guid>
      <dc:creator>Gonzalo</dc:creator>
      <dc:date>2020-01-09T08:59:44Z</dc:date>
    </item>
  </channel>
</rss>

