<?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 Retrieve record based on table expression in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Retrieve-record-based-on-table-expression/m-p/954782#M328211</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to know how to retrieve the appropriate record in the following scenario:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table with an expression "Demand" which is the distinct count of a field value. Simple. The records counted are based not just on a selection, but on a variable date range specified by variables in input boxes. I give this exposition because it does not seem that my solution lies in the script. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nevertheless, as indicated by the image attached, I would like to determine the appropriate Stock Qty value to return by finding the record whose Min/Max Threshold range contains the value I calculate in "Demand". Any pointers? I'm sure there's a function I'm failing to consider or implement properly. There has to be an easy way to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;demand = count({&amp;lt;[End Date]={"&amp;gt;=$(vStartDate)"},[Start Date]={"&amp;lt;=$(vEndDate)"}&amp;gt;} distinct [Serial Number])&lt;/P&gt;&lt;P&gt;stock qty = ???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The ugly and unscalable way of doing this is: &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;=if(Demand&amp;gt;=min([Threshold Min]) and Demand&amp;lt;=min([Threshold Max]),&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; min([Stock Qty]),&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],2) and Demand&amp;lt;=min([Threshold Max],2),&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; min([Stock Qty],2),&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],3) and Demand&amp;lt;=min([Threshold Max],3),&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; min([Stock Qty],3),&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],4) and Demand&amp;lt;=min([Threshold Max],4),&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; min([Stock Qty],4),&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],5) and Demand&amp;lt;=min([Threshold Max],5),&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; min([Stock Qty],5),&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; 0)))))&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/106255_Capture.PNG" style="height: 194px; width: 620px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Nov 2015 18:27:31 GMT</pubDate>
    <dc:creator>richardpayne</dc:creator>
    <dc:date>2015-11-20T18:27:31Z</dc:date>
    <item>
      <title>Retrieve record based on table expression</title>
      <link>https://community.qlik.com/t5/QlikView/Retrieve-record-based-on-table-expression/m-p/954782#M328211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to know how to retrieve the appropriate record in the following scenario:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table with an expression "Demand" which is the distinct count of a field value. Simple. The records counted are based not just on a selection, but on a variable date range specified by variables in input boxes. I give this exposition because it does not seem that my solution lies in the script. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nevertheless, as indicated by the image attached, I would like to determine the appropriate Stock Qty value to return by finding the record whose Min/Max Threshold range contains the value I calculate in "Demand". Any pointers? I'm sure there's a function I'm failing to consider or implement properly. There has to be an easy way to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;demand = count({&amp;lt;[End Date]={"&amp;gt;=$(vStartDate)"},[Start Date]={"&amp;lt;=$(vEndDate)"}&amp;gt;} distinct [Serial Number])&lt;/P&gt;&lt;P&gt;stock qty = ???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The ugly and unscalable way of doing this is: &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;=if(Demand&amp;gt;=min([Threshold Min]) and Demand&amp;lt;=min([Threshold Max]),&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; min([Stock Qty]),&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],2) and Demand&amp;lt;=min([Threshold Max],2),&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; min([Stock Qty],2),&lt;/P&gt;&lt;P style="padding-left: 60px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],3) and Demand&amp;lt;=min([Threshold Max],3),&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; min([Stock Qty],3),&lt;/P&gt;&lt;P style="padding-left: 90px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],4) and Demand&amp;lt;=min([Threshold Max],4),&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; min([Stock Qty],4),&lt;/P&gt;&lt;P style="padding-left: 120px;"&gt;&amp;nbsp; if(Demand&amp;gt;=min([Threshold Min],5) and Demand&amp;lt;=min([Threshold Max],5),&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; min([Stock Qty],5),&lt;/P&gt;&lt;P style="padding-left: 150px;"&gt;&amp;nbsp; 0)))))&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/106255_Capture.PNG" style="height: 194px; width: 620px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 18:27:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Retrieve-record-based-on-table-expression/m-p/954782#M328211</guid>
      <dc:creator>richardpayne</dc:creator>
      <dc:date>2015-11-20T18:27:31Z</dc:date>
    </item>
  </channel>
</rss>

