<?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 Using Set Analysis to &amp;quot;Lookup&amp;quot; Corresponding Value in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329223#M581556</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have considered going back to the script to introducing the opportunity cost as a new measure (This is how we do it in the OLAP cube that sits on top of the fact table.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But ultimately what I was hoping was that we wouldn't have to go to the scripts to be able to generate this sort of expression, so that our users could come up with these sorts of calculations (of which there are many more above and beyond this one example) and we could supply them with the syntax to achieve it without a script load.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Nov 2011 22:48:12 GMT</pubDate>
    <dc:creator />
    <dc:date>2011-11-18T22:48:12Z</dc:date>
    <item>
      <title>Using Set Analysis to "Lookup" Corresponding Value</title>
      <link>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329221#M581549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a fact table with the following (simplified) structure:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DealID, RecordType, Date, Price, Volume&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It has (again, simplified) 5 rows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" height="137" style="width: 370px; height: 132px; border-width: 1px; border-color: #000000; border-style: solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;DealID&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;RecordType&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Date&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Price&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Volume&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Hedge Deal&lt;/TD&gt;&lt;TD&gt;1-1-2011&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Hedge Deal&lt;/TD&gt;&lt;TD&gt;1-1-2011&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Hedge Deal&lt;/TD&gt;&lt;TD&gt;1-1-2011&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Hedge Deal&lt;/TD&gt;&lt;TD&gt;1-1-2011&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;Market Price&lt;/TD&gt;&lt;TD&gt;1-1-2011&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;NULL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to create a pie chart that measures opportunity cost by month. That is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Take the hedge price minus the daily market price * the hedge volume for each hedge deal and call that opportunity cost.&lt;/P&gt;&lt;P&gt;2) Sum this by month.&lt;/P&gt;&lt;P&gt;3) Have month as a dimension and this sum as the expression.&lt;/P&gt;&lt;P&gt;4) Pie chart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is I can't find a way to "look up" the daily market price for each hedge deal. I've tried using the different functions for this (set analysis, aggr(), etc.) but I keep running into the same two problems:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) I have to include Date and DealID in the dimensions to properly do the opportunity cost math, and then I can't do an aggregrated pie chart.&lt;/P&gt;&lt;P&gt;2) If I just use Month(Date) as the dimension, I can't figure out how to do the opportunity cost math on a per-deal basis - if I use average price, it aggregates to the month and you lose the individual variance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(If you want to check your math, the opportunity cost for January here is -10,000.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, I keep getting tantalizingly close to the solution, so I'm pretty sure it's possible, so if anyone can push me in the right direction, I would appreciate it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Kyle Hale&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Nov 2011 21:38:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329221#M581549</guid>
      <dc:creator />
      <dc:date>2011-11-18T21:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using Set Analysis to "Lookup" Corresponding Value</title>
      <link>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329222#M581553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see no advantage to set analysis over a script solution, even if we could come up with an expression that worked.&amp;nbsp; The opportunity cost calculation can be done per ID, so it isn't a script aggregation (which we'd want to avoid).&amp;nbsp; We're just saving the user objects time, and making our expressions simpler.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See attached.&amp;nbsp; Script below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Data:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD * INLINE [&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;DealID RecordType Date Price Volume &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;1 'Hedge Deal' 1-1-2011 25 500 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;2 'Hedge Deal' 1-1-2011 30 200 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;3 'Hedge Deal' 1-1-2011 35 300 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;4 'Hedge Deal' 1-1-2011 50 100 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;5 'Market Price' 1-1-2011 40&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;] (delimiter is ' ');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LEFT JOIN (Data)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;'Hedge Deal' as RecordType&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,Date&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,Price as MarketPrice&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;RESIDENT Data&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;WHERE RecordType = 'Market Price'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LEFT JOIN (Data)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;DealID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;, (Price - MarketPrice) * Volume as OpportunityCost&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;RESIDENT Data&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;WHERE RecordType = 'Hedge Deal'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;DROP FIELD MarketPrice&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;[Calendar]:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,date(monthstart(Date),'MMM YYYY') as Month&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD date(fieldvalue('Date',recno())) as Date&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;AUTOGENERATE fieldvaluecount('Date')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Nov 2011 22:05:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329222#M581553</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-11-18T22:05:19Z</dc:date>
    </item>
    <item>
      <title>Using Set Analysis to "Lookup" Corresponding Value</title>
      <link>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329223#M581556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have considered going back to the script to introducing the opportunity cost as a new measure (This is how we do it in the OLAP cube that sits on top of the fact table.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But ultimately what I was hoping was that we wouldn't have to go to the scripts to be able to generate this sort of expression, so that our users could come up with these sorts of calculations (of which there are many more above and beyond this one example) and we could supply them with the syntax to achieve it without a script load.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Nov 2011 22:48:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329223#M581556</guid>
      <dc:creator />
      <dc:date>2011-11-18T22:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Set Analysis to "Lookup" Corresponding Value</title>
      <link>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329224#M581559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One of the fundamental limitations with set analysis is that a set is built at the level of the entire chart, not at the level of a row on the chart.&amp;nbsp; So a set expression designed to do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;(Price - only({lookup the market price record for the date} Price)) * Volume&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would stop working the moment there was more than one date.&amp;nbsp; And of course if there was only one date, there's be no need for a lookup.&amp;nbsp; In other words, you can't use set analysis to do a lookup, or at least I personally don't think it's possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, I'm not entirely sure why the firstsortedvalue() portion of the below expression works, but it seems to work, and the whole expression seems to work.&amp;nbsp; There's probably a simpler expression, but this is what I have.&amp;nbsp; This of course isn't something I'd ask a user to type in.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum(aggr(&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Volume * (only({&amp;lt;RecordType={'Hedge Deal'}&amp;gt;} Price) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;- aggr(nodistinct firstsortedvalue({&amp;lt;RecordType={'Market Price'}&amp;gt;} Price,Date),Month,Date))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,Month,Date,DealID))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See attached.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Nov 2011 00:12:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-Set-Analysis-to-quot-Lookup-quot-Corresponding-Value/m-p/329224#M581559</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-11-19T00:12:15Z</dc:date>
    </item>
  </channel>
</rss>

