<?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: Dynamic Set Expression inside a Set Expression in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329545#M410889</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sunny,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the reply. That expression doesn't satisfy the conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stock 123 &amp;amp; 567 should not be in the table as more than 50% of the Purchase Qty has been sold.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think vTest50 is the problem, as I know it contains the incorrect expression for Purchased Qty and Sold Qty&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Jun 2017 09:15:25 GMT</pubDate>
    <dc:creator>whiteymcaces</dc:creator>
    <dc:date>2017-06-21T09:15:25Z</dc:date>
    <item>
      <title>Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329541#M410885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I have an easy question, however, I must be having a mental block, as the answer escapes me. Hopefully, someone can assist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a Fact table with a mixture of Stock Purchase information and Stock Sales information.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My ultimate goal is to show a list of Stock Items (in a straight table) that were Purchased more than 3 months ago, and have only sold less than 50% of the Purchase Qty.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Conditions:&lt;/P&gt;&lt;P&gt;1. Only show Stock Items that have sold less than 50% of Purchase Qty&lt;/P&gt;&lt;P&gt;2. Only show Stock Items that are associated with the most recent Purchase, before 3 month ago (eg, if I have 3 Purchases dated 01-Mar-2017, 15-Mar-2017, 10-Apr-2017, and today = 21-Jun-2017, I only want Stock Items on the 15-Mar-2017)&lt;/P&gt;&lt;P&gt;3. The main dimension will be Stock Item, and each Stock Item must satisfy Conditions 1. and 2.&lt;/P&gt;&lt;P&gt;4. A variable is required to determine when 3 months ago is.&lt;/P&gt;&lt;P&gt;5. Purchase Qty is calculated on or before the date variable.&lt;/P&gt;&lt;P&gt;6. Sales Qty is calculated on or after the date variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Columns to be shown will be:-&lt;/P&gt;&lt;P&gt;Stock Item&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dimension&lt;/P&gt;&lt;P&gt;Item Description&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dimension&lt;/P&gt;&lt;P&gt;Purchase Qty&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression&lt;/P&gt;&lt;P&gt;Sold Qty&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression&lt;/P&gt;&lt;P&gt;Last Purchase Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression&lt;/P&gt;&lt;P&gt;Last Sold Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first issue surrounds calculating the Purchase Qty and the Sold Qty, as these are required to restrict the Stock Items shown.&lt;/P&gt;&lt;P&gt;I believe I will need an If condition on every Expression to achieve the correct Stock List.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;If((Sold Qty / Purchased Qty) &amp;lt; 0.5, Some Expression, 0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both Sold Qty and Purchased Qty are tricky, as both are based on the Last Purchase Date and each Stock Item (each Row) will have a different Date that the Purchase was done. It could be any date before the variable date (vDate3Mths).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Sales - Expression would be like Sum({&amp;lt;Date = {All dates after the Last Purchase Date}&amp;gt;} Qty * isSLine)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I thought may work Sum({&amp;lt;Date = {"=$(=Max({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date))"}&amp;gt;} Qty * isSLine)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This part is what I use to calculate the latest Purchase date before the variable date&lt;/P&gt;&lt;P&gt;Max({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when used inside another Set Expression, it is not dynamic for each Stock Item. I think I need to somehow use Aggr() function, however, not sure of the syntax.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The exact same issue is with the Purchased Qty&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attached a simple example .qvw&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 07:12:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329541#M410885</guid>
      <dc:creator>whiteymcaces</dc:creator>
      <dc:date>2017-06-21T07:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329542#M410886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How you are calculating 3 months before here?&lt;/P&gt;&lt;P&gt;I mean with respect to today's date?&lt;/P&gt;&lt;P&gt;If yes, provide data accordingly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 08:00:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329542#M410886</guid>
      <dc:creator>MK_QSL</dc:creator>
      <dc:date>2017-06-21T08:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329543#M410887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Manish,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my real QlikView document the expression for vDate3Mths:&lt;/P&gt;&lt;P&gt;=Date(AddMonths(Max({&amp;lt;isSLine = {1}&amp;gt;} Date), -3))&lt;/P&gt;&lt;P&gt;Which calculates 3 months before the latest Sales Invoice (Which may not be today() or the date of reload. Done this as there is Budget data for the entire year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my example qvw, which you have, I use a similar Expression:&lt;/P&gt;&lt;P&gt;=Date(Max(Date) - 2)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The concept is the same. Changing the example qvw variable to =Date(Max({&amp;lt;isSLine = {1}&amp;gt;} Date) - 2) is essentially the same and should demonstrate the same result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't provide data due to client confidentiality, and size of document.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 08:13:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329543#M410887</guid>
      <dc:creator>whiteymcaces</dc:creator>
      <dc:date>2017-06-21T08:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329544#M410888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May be this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sum({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;}Aggr(If($(vTest50) and Date = Max(TOTAL &amp;lt;Stock&amp;gt;{&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date), Max({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Qty), 0), Stock, Date))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/167594_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 08:43:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329544#M410888</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-06-21T08:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329545#M410889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sunny,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the reply. That expression doesn't satisfy the conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stock 123 &amp;amp; 567 should not be in the table as more than 50% of the Purchase Qty has been sold.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think vTest50 is the problem, as I know it contains the incorrect expression for Purchased Qty and Sold Qty&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 09:15:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329545#M410889</guid>
      <dc:creator>whiteymcaces</dc:creator>
      <dc:date>2017-06-21T09:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329546#M410890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May be try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sum({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; Aggr(&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; If(&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; Sum(TOTAL &amp;lt;Stock&amp;gt; {&amp;lt;Date = {'&amp;gt;=$(vDate3Mths)'}&amp;gt;} Qty * isSLine) / Max(TOTAL &amp;lt;Stock&amp;gt;{&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Qty) &amp;lt; 0.5 and&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; Date = Max(TOTAL &amp;lt;Stock&amp;gt;{&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date) and&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; Sum(TOTAL &amp;lt;Stock&amp;gt; {&amp;lt;Date = {'&amp;gt;=$(vDate3Mths)'}&amp;gt;} Qty * isSLine) &amp;gt; 0,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; Max({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Qty), 0)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; , Stock, Date))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/167605_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 11:06:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329546#M410890</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-06-21T11:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329547#M410891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sunny,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I decided to use a version of this response. Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vTest50 = Sum(Aggr(If(Date &amp;gt;= Max(TOTAL &amp;lt;Stock&amp;gt;{&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date), Sum(Qty * isSLine), 0), Stock, Date)) / Sum({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Aggr(If(Date = Max(TOTAL &amp;lt;Stock&amp;gt;{&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date), Max({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Qty), 0), Stock, Date)) &amp;lt; 0.5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Last Purchase = If($(vTest50), Max({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date), Null())&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Last Sale = If($(vTest50), Max({&amp;lt;isSLine = {1}&amp;gt;} Date), Null())&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Purchase Qty = If($(vTest50), Sum({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;}Aggr(If(Date = Max(TOTAL &amp;lt;Stock&amp;gt;{&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date), Max({&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Qty), 0), Stock, Date)), Null())&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sold Qty = If($(vTest50), Sum(Aggr(If(Date &amp;gt;= Max(TOTAL &amp;lt;Stock&amp;gt;{&amp;lt;isPLine = {1}, Date = {'&amp;lt;=$(vDate3Mths)'}&amp;gt;} Date), Sum(Qty * isSLine), 0), Stock, Date)), Null())&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 14:46:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329547#M410891</guid>
      <dc:creator>whiteymcaces</dc:creator>
      <dc:date>2017-06-21T14:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Set Expression inside a Set Expression</title>
      <link>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329548#M410892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So everything working then? If it is, I would suggest you to close this thread by marking correct response&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/docs/DOC-14806"&gt;Qlik Community Tip: Marking Replies as Correct or Helpful&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sunny&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jun 2017 14:50:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Dynamic-Set-Expression-inside-a-Set-Expression/m-p/1329548#M410892</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-06-21T14:50:07Z</dc:date>
    </item>
  </channel>
</rss>

