<?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: Looking Up Value based on Week Number in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Looking-Up-Value-based-on-Week-Number/m-p/1993521#M82222</link>
    <description>&lt;P&gt;Hi Simon,&lt;/P&gt;
&lt;P&gt;You are almost there, but you need to use a very particular syntax in your Set Analysis condition. You can't simply write "field = formula", instead you need to always enclose the "selected" values in curly brackets {...} and if you need to calculate something, you should enclose your calculation in a $-sign expansion. Your syntax should look like this:&lt;/P&gt;
&lt;P&gt;=Max({&amp;lt;[TargetTable.Week Number] =&lt;STRONG&gt; {$(=&lt;/STRONG&gt;Max([Orders.Week Number])&lt;STRONG&gt;)}&lt;/STRONG&gt;&amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;This is in case you want the max([Orders.Week Number]) to respect user selections. If you want an absolute maximum, no matter what is selected, then add another Set Analysis {1} in that aggregation:&lt;/P&gt;
&lt;P&gt;=Max({&amp;lt;[TargetTable.Week Number] =&lt;STRONG&gt; {$(=&lt;/STRONG&gt;Max(&lt;STRONG&gt;{1}&lt;/STRONG&gt; [Orders.Week Number])&lt;STRONG&gt;)}&lt;/STRONG&gt;&amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;I'd even recommend to define a variable and calculate it outside of your set analysis, to improve performance of this formula:&lt;/P&gt;
&lt;P&gt;set vMaxWeek = '&lt;STRONG&gt;=&lt;/STRONG&gt;Max(&lt;STRONG&gt;{1}&lt;/STRONG&gt; [Orders.Week Number])'; // Notice that the formula should begin with the equals sign&lt;/P&gt;
&lt;P&gt;Then you can use the variable in your Set Analysis condition, and it will work better:&lt;/P&gt;
&lt;P&gt;=Max({&amp;lt;[TargetTable.Week Number] =&lt;STRONG&gt; {$(vMaxWeek&lt;/STRONG&gt;&lt;STRONG&gt;)}&lt;/STRONG&gt;&amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;Join us at the &lt;A href="https://masterssummit.com" target="_self"&gt;Masters Summit for Qlik&lt;/A&gt; in New Orleans on November 14-16 to learn these and many other advanced development techniques!&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2022 18:18:07 GMT</pubDate>
    <dc:creator>Oleg_Troyansky</dc:creator>
    <dc:date>2022-10-17T18:18:07Z</dc:date>
    <item>
      <title>Looking Up Value based on Week Number</title>
      <link>https://community.qlik.com/t5/App-Development/Looking-Up-Value-based-on-Week-Number/m-p/1993382#M82211</link>
      <description>&lt;P&gt;I'm trying to return a value based on the Highest Week Number in our Data.&lt;/P&gt;
&lt;P&gt;The below works with the Highest Week Number hardcoded into the formula as shown below.&lt;BR /&gt;=Max({&amp;lt;[TargetTable.Week Number] ={42} &amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;However, when I replace the hardcoded Week Number with the formula to return the highest week number 'Max([Orders.Week Number])' as shown below,&amp;nbsp; I get an error reading&amp;nbsp;&lt;EM&gt;Error in Set Modifier ad hoc element list: ';' or ')' expected&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;=Max({&amp;lt;[TargetTable.Week Number] =Max([Orders.Week Number])&amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;Below are snippets of the 2 relevant tables&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 132pt;" border="0" width="176" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD width="88" height="22" style="height: 16.5pt; width: 66pt;"&gt;TargetTable&lt;/TD&gt;
&lt;TD width="88" style="width: 66pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" style="height: 16.5pt;"&gt;Week Number&lt;/TD&gt;
&lt;TD&gt;Target %&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;40&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;80%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;41&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;81%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;42&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;82%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;43&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;83%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;44&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;84%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;45&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;85%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;46&lt;/TD&gt;
&lt;TD align="right" class="xl63"&gt;86%&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 132pt;" border="0" width="176" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD width="88" height="22" style="height: 16.5pt; width: 66pt;"&gt;Orders&lt;/TD&gt;
&lt;TD width="88" style="width: 66pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" style="height: 16.5pt;"&gt;OrderID&lt;/TD&gt;
&lt;TD&gt;Week Number&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1567&lt;/TD&gt;
&lt;TD align="right"&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1568&lt;/TD&gt;
&lt;TD align="right"&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1569&lt;/TD&gt;
&lt;TD align="right"&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1570&lt;/TD&gt;
&lt;TD align="right"&gt;41&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1571&lt;/TD&gt;
&lt;TD align="right"&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1572&lt;/TD&gt;
&lt;TD align="right"&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1573&lt;/TD&gt;
&lt;TD align="right"&gt;41&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1574&lt;/TD&gt;
&lt;TD align="right"&gt;40&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD height="22" align="right" style="height: 16.5pt;"&gt;1575&lt;/TD&gt;
&lt;TD align="right"&gt;41&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 14:45:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Looking-Up-Value-based-on-Week-Number/m-p/1993382#M82211</guid>
      <dc:creator>simoncarts</dc:creator>
      <dc:date>2022-10-17T14:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Looking Up Value based on Week Number</title>
      <link>https://community.qlik.com/t5/App-Development/Looking-Up-Value-based-on-Week-Number/m-p/1993521#M82222</link>
      <description>&lt;P&gt;Hi Simon,&lt;/P&gt;
&lt;P&gt;You are almost there, but you need to use a very particular syntax in your Set Analysis condition. You can't simply write "field = formula", instead you need to always enclose the "selected" values in curly brackets {...} and if you need to calculate something, you should enclose your calculation in a $-sign expansion. Your syntax should look like this:&lt;/P&gt;
&lt;P&gt;=Max({&amp;lt;[TargetTable.Week Number] =&lt;STRONG&gt; {$(=&lt;/STRONG&gt;Max([Orders.Week Number])&lt;STRONG&gt;)}&lt;/STRONG&gt;&amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;This is in case you want the max([Orders.Week Number]) to respect user selections. If you want an absolute maximum, no matter what is selected, then add another Set Analysis {1} in that aggregation:&lt;/P&gt;
&lt;P&gt;=Max({&amp;lt;[TargetTable.Week Number] =&lt;STRONG&gt; {$(=&lt;/STRONG&gt;Max(&lt;STRONG&gt;{1}&lt;/STRONG&gt; [Orders.Week Number])&lt;STRONG&gt;)}&lt;/STRONG&gt;&amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;I'd even recommend to define a variable and calculate it outside of your set analysis, to improve performance of this formula:&lt;/P&gt;
&lt;P&gt;set vMaxWeek = '&lt;STRONG&gt;=&lt;/STRONG&gt;Max(&lt;STRONG&gt;{1}&lt;/STRONG&gt; [Orders.Week Number])'; // Notice that the formula should begin with the equals sign&lt;/P&gt;
&lt;P&gt;Then you can use the variable in your Set Analysis condition, and it will work better:&lt;/P&gt;
&lt;P&gt;=Max({&amp;lt;[TargetTable.Week Number] =&lt;STRONG&gt; {$(vMaxWeek&lt;/STRONG&gt;&lt;STRONG&gt;)}&lt;/STRONG&gt;&amp;gt;} [TargetTable.Target %])&lt;/P&gt;
&lt;P&gt;Join us at the &lt;A href="https://masterssummit.com" target="_self"&gt;Masters Summit for Qlik&lt;/A&gt; in New Orleans on November 14-16 to learn these and many other advanced development techniques!&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 18:18:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Looking-Up-Value-based-on-Week-Number/m-p/1993521#M82222</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2022-10-17T18:18:07Z</dc:date>
    </item>
  </channel>
</rss>

