<?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: Extracting unique values for aggregation - patient data in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358347#M824016</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Louise,&lt;/P&gt;&lt;P&gt;Maybe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Average total cost per patient as a KPI&lt;/P&gt;&lt;P&gt;avg(Aggr(sum(total_cost),patient_id)) = 3375&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;Average total cost per patient associated with each diagnosis&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" style="font-size: 9pt;"&gt;&lt;TBODY&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;diagnosis&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;avg(Aggr(sum(total_cost),patient_id,diagnosis)) &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1875&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah2&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1750&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah3&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 25 Jul 2017 08:29:36 GMT</pubDate>
    <dc:creator>effinty2112</dc:creator>
    <dc:date>2017-07-25T08:29:36Z</dc:date>
    <item>
      <title>Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358343#M824012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 434px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="154"&gt;patient_id&lt;/TD&gt;&lt;TD width="152"&gt;Episode Number&lt;/TD&gt;&lt;TD width="64"&gt;diagnosis&lt;/TD&gt;&lt;TD width="64"&gt;total_cost&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;12a&lt;/TD&gt;&lt;TD&gt;1x&lt;/TD&gt;&lt;TD&gt;blah1&lt;/TD&gt;&lt;TD align="right"&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;12a&lt;/TD&gt;&lt;TD&gt;2y&lt;/TD&gt;&lt;TD&gt;blah2&lt;/TD&gt;&lt;TD align="right"&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;13b&lt;/TD&gt;&lt;TD&gt;4z&lt;/TD&gt;&lt;TD&gt;blah1&lt;/TD&gt;&lt;TD align="right"&gt;3000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;14c&lt;/TD&gt;&lt;TD&gt;5x&lt;/TD&gt;&lt;TD&gt;blah1&lt;/TD&gt;&lt;TD align="right"&gt;2500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;14c&lt;/TD&gt;&lt;TD&gt;6z&lt;/TD&gt;&lt;TD&gt;blah2&lt;/TD&gt;&lt;TD align="right"&gt;2500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;14c&lt;/TD&gt;&lt;TD&gt;9x&lt;/TD&gt;&lt;TD&gt;blah3&lt;/TD&gt;&lt;TD align="right"&gt;2500&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;15d&lt;/TD&gt;&lt;TD&gt;8y&lt;/TD&gt;&lt;TD&gt;blah1&lt;/TD&gt;&lt;TD align="right"&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope I have posted this in the right place. If not let me know.&lt;/P&gt;&lt;P&gt;I have a large file and I have recreated the format in the example above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each patient_id is unique in the real world but each patient may have more than one episode number (also unique) and within each episode they may have more than one diagnosis (not unique). The presence of a few diagnosis/episodes for each patient means that the unique patient_ID and the total_costs for each patient appear more than once in the flat file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="text-decoration: underline;"&gt;I need to create a measure that extracts the total cost for each unique patient_id so that I can create an overall average total cost per patient as a KPI.&lt;/STRONG&gt; I then need to use this measure in a chart with diagnosis as the dimension so i can then see the average total cost per patient associated with each diagnosis (or other fields I have in the real table).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So basically i need to sum the total cost for unique episode numbers and then sum these answers for the unique patient id's&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;When I just use avg(total_cost) - the results are way to high&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apologies in advance if there is something simple I am missing here but I am struggling with this. As a first step I've tried&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sum(aggr(max([Episode Number]), total_cost)/count(aggr(max([Episode Number]),distinct [Episode Number])))&amp;nbsp; &lt;/STRONG&gt;in an effort to start by pick out the unique episode ids using max and use aggr to create a temp table and then sum the total costs over this. I am then trying to divide by the number of unique Episode Numbers by counting them. This expression is not throwing an error but it is giving me a blank chart. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On top of this, I just cannot get to the next level and figure out how to work the unique patient_id's into this expression so the average is actually based on these.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help much appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;kindest regards,&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358343#M824012</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358344#M824013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let me know if this is what you are looking for.&lt;/P&gt;&lt;P&gt;I have tried to get the avg by patient &amp;amp; Episode number with multiple methods.&lt;/P&gt;&lt;P&gt;Let me know if you are looking for different output.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jul 2017 19:17:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358344#M824013</guid>
      <dc:creator>neelamsaroha157</dc:creator>
      <dc:date>2017-07-24T19:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358345#M824014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@I really appreciate the time you have taken to help with this. Unfortunately, I can't open your qlikview .qvw file as I am working in either QlikSense server or Qliksense desktop. I can see only the load script and the data model when i try to open it in qliksense. I can only open .qvf files. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is not too much trouble could you post the actual expressions you have compiled and I will try and replicate them? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;kind regards,&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 07:56:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358345#M824014</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2017-07-25T07:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358346#M824015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;how about&lt;/P&gt;&lt;P&gt;avg(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; aggr(&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(total_cost),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; patient_id)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/P&gt;&lt;P&gt;?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 08:07:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358346#M824015</guid>
      <dc:creator>marcus_malinow</dc:creator>
      <dc:date>2017-07-25T08:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358347#M824016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Louise,&lt;/P&gt;&lt;P&gt;Maybe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Average total cost per patient as a KPI&lt;/P&gt;&lt;P&gt;avg(Aggr(sum(total_cost),patient_id)) = 3375&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;Average total cost per patient associated with each diagnosis&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" style="font-size: 9pt;"&gt;&lt;TBODY&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;diagnosis&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;avg(Aggr(sum(total_cost),patient_id,diagnosis)) &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1875&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah2&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1750&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah3&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 08:29:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358347#M824016</guid>
      <dc:creator>effinty2112</dc:creator>
      <dc:date>2017-07-25T08:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358348#M824017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Marcus - I've had a look at that - I need to take the average total costs &lt;SPAN style="text-decoration: underline;"&gt;of the distinct episode numbers&lt;/SPAN&gt; for each patient before I then take the average of those figures calculated on each distinct patient id. Which i think is a nested aggregation and not allowed?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 08:30:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358348#M824017</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2017-07-25T08:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358349#M824018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andrew, &lt;/P&gt;&lt;P&gt;Thank you for that, again much appreciated, but I have the same problem there, yes it looks like that is giving me an average of the total costs for each patient but before that calculation, I need to ensure that each patients total cost value is comprised of the total of his episode number costs. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the real world - a patient might come to the hospital once - he has one episode that costs €1000 - that is the figure used in the sum part of the calculation of the average cost for a patient - simple enough.&lt;/P&gt;&lt;P&gt;However in some cases the patient will present at the hospital 2 or 3 times each time has a unique episode number and is associated with its own cost. These costs have to be summed for each patient to get their real total cost figure and it is this figure that is included in the 'average per patient' calculation. This is the bit I am missing prior to the average for each patient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not too worried about the diagnosis as I can just pick that as a dimension on a chart once I have the expression for doing the above calculation sorted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apologies for melting peoples heads.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 08:43:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358349#M824018</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2017-07-25T08:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358350#M824019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To clarify - in the above example patient 14 c has 3 episode numbers (5x, 6z and 9x) each with an associated cost of (2500, 2500 and 2500 respectively - terrible example - should have made those numbers different), the costs for each of these has to be summed to get the total cost for patient 14c (which is 2500 +2500+2500 = 7500), that is the total cost used for patient 14 c when the average total cost per patient is being calculated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 09:05:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358350#M824019</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2017-07-25T09:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358351#M824020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Louise,&lt;/P&gt;&lt;P&gt;Apologies if I'm not following you but do you want the average cost of diagnosis per patient?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=avg(aggr(Sum(total_cost),diagnosis,patient_id))&lt;/P&gt;&lt;P&gt;1928.5714&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" style="font-size: 9pt;"&gt;&lt;TBODY&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;diagnosis&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;avg(Aggr(sum(total_cost),patient_id,diagnosis)) &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1928.5714 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1875&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah2&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1750&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah3&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Switching the dimension give the same overall average&lt;/P&gt;&lt;TABLE bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" style="font-size: 9pt;"&gt;&lt;TBODY&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;patient_id&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;avg(Aggr(sum(total_cost),patient_id,diagnosis)) &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1928.5714 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;12a&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;15d&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;14c&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;13b&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;3000&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 09:40:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358351#M824020</guid>
      <dc:creator>effinty2112</dc:creator>
      <dc:date>2017-07-25T09:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358352#M824021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you can provide the expected output for your above data, that will be helpful to give you exactly what you want&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 09:55:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358352#M824021</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2017-07-25T09:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358353#M824022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Louise,&lt;/P&gt;&lt;P&gt;I thought the Episode Numbers were unique. Why the emphasis then on&lt;SPAN style="text-decoration: underline;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #3d3d3d; font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; text-decoration: underline;"&gt;distinct episode numbers&lt;/SPAN&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt; ? &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/confused.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If unique then there would be a single cost associated with each one, no?&lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 10:44:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358353#M824022</guid>
      <dc:creator>effinty2112</dc:creator>
      <dc:date>2017-07-25T10:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358354#M824023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333px;"&gt;Hi kushal -thanks for your time on this,&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;In the real file there is potential for more than one diagnosis being associated with each episode for each patient (that is the only relevance of diagnosis in this question). Because there can be more than one diagnosis associated with an episode, it means that the same episode number might appear more than once for a patient_id. And because the same patient might have more than one episode the same patient_id might appear more than once in the file. (even though both these numbers are unique identifiers of patients and their episodes in the real world)&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Bearing all that in mind I need the average cost per patient&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;The sample calculation would be as follows.....&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;total cost for patient 12a is calculated by adding the total costs for each of his episode numbers making sure to only &lt;SPAN style="text-decoration: underline;"&gt;p&lt;/SPAN&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;ull out costs for unique episode numbers&lt;/STRONG&gt;&lt;/SPAN&gt; (1x + 2y) =1000+1000 = €2000, in my real file they may not be unique because of the diagnosis codes.&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;total cost for patient 13b is €3000 (he only has one episode number 4z)&lt;/LI&gt;&lt;LI&gt;total cost for patient 14c is calculated by adding the total costs for each of his episode numbers, making sure to only pull out total costs for unique episode numbers (5x, 6z, 9x) = 2500 +2500+2500 = €7500&lt;/LI&gt;&lt;LI&gt;total cost for patient 15d is €1000 (he only has one episode number 8y)&lt;/LI&gt;&lt;/UL&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;the &lt;SPAN style="text-decoration: underline;"&gt;average cost per patient&lt;/SPAN&gt; is calculated by summing the total cost for each unique patient (12a=€2000, 13b=€3000,14c=€7500,15f=€1000) and dividing by the number of unique patients (4)&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;(2000+3000+7500+1000)/4 = 3375&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;As opposed to just averaging all the costs &lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;1000+1000+3000+2500+2500+2500+1000/7 = 1928.57&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;I need to make sure that the overall average reflects the fact that patient 14c actually has a total cost of €7500 as opposed to being calculated on the assumption that there are 3 patients with lower costs because the expression pulls out the same patient number 3 times for the average. The uniqueness is important. This becomes important as I will also need to adjust the expression from calculating average to calculating median for other purposes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Apologies for long message and if I am missing something obvious.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 11:08:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358354#M824023</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2017-07-25T11:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358355#M824024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Andrew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think your answer for average total cost per patient is right but I am puzzled as to how it is being calculated as there is no part of the expression that is summing the total costs for each unique episode_id. The only relevance of diagnosis is that I may choose it as a dimension in a chart to get the values for each - so don't worry about that if constructing the expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If helpful, I've attached a copy of my answer to Kushal here where he requested what I would like the result to be and how I would like it calculated. It is a bit long winded but I am trying to ensure all relevant information is present.&lt;/P&gt;&lt;P&gt;all time &amp;amp; thoughts much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;Hi kushal -thanks for your time on this,&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;In the real file there is potential for more than one diagnosis being associated with each episode for each patient (that is the only relevance of diagnosis in this question). Because there can be more than one diagnosis associated with an episode, it means that the same episode number might appear more than once for a patient_id. And because the same patient might have more than one episode the same patient_id might appear more than once in the file. (even though both these numbers are unique identifiers of patients and their episodes in the real world)&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;Bearing all that in mind about the underlying data table structure, I still need to extract the average cost per patient&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;The sample calculation would be as follows.....&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;total cost for patient 12a is calculated by adding the total costs for each of his episode numbers making sure to only &lt;SPAN style="font-weight: inherit; font-family: inherit;"&gt;p&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;ull out costs for unique episode numbers&lt;/STRONG&gt;&lt;/SPAN&gt; (1x + 2y) =1000+1000 = €2000, in my real file they may not be unique because of the diagnosis codes.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;total cost for patient 13b is €3000 (he only has one episode number 4z)&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;total cost for patient 14c is calculated by adding the total costs for each of his episode numbers, making sure to only pull out total costs for unique episode numbers (5x, 6z, 9x) = 2500 +2500+2500 = €7500&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;total cost for patient 15d is €1000 (he only has one episode number 8y)&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;the &lt;SPAN style="font-weight: inherit; font-size: 13.3333px; font-family: inherit;"&gt;average cost per patient&lt;/SPAN&gt; is calculated by summing the total cost for each unique patient (12a=€2000, 13b=€3000,14c=€7500,15f=€1000) and dividing by the number of unique patients (4)&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;(2000+3000+7500+1000)/4 = 3375&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;As opposed to just averaging all the costs&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;1000+1000+3000+2500+2500+2500+1000/7 = 1928.57&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM style="font-size: 13.3333px; font-family: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM style="font-size: 13.3333px; font-family: inherit; font-weight: inherit;"&gt;I need to make sure that the overall average reflects the fact that patient 14c actually has a total cost of €7500 as opposed to being calculated on the assumption that there are 3 patients with lower costs because the expression pulls out the same patient number 3 times for the average. The uniqueness is important. This becomes important as I will also need to adjust the expression from calculating average to calculating median for other purposes.&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;Apologies for long message and if I am missing something obvious.&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;Louise&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 11:19:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358355#M824024</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2017-07-25T11:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358356#M824025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you can try something like below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;LOAD * Inline [&lt;/P&gt;&lt;P&gt;patient_id Episode Number diagnosis total_cost&lt;/P&gt;&lt;P&gt;12a 1x blah1 1000&lt;/P&gt;&lt;P&gt;12a 2y blah2 1000&lt;/P&gt;&lt;P&gt;13b 4z blah1 3000&lt;/P&gt;&lt;P&gt;14c 5x blah1 2500&lt;/P&gt;&lt;P&gt;14c 6z blah2 2500&lt;/P&gt;&lt;P&gt;14c 9x blah3 2500&lt;/P&gt;&lt;P&gt;15d 8y blah1 1000&amp;nbsp; ] (delimiter is '\t');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left Join(Data)&lt;/P&gt;&lt;P&gt;LOAD patient_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(total_cost) as TotalCostPatientWise&lt;/P&gt;&lt;P&gt;Resident Data&lt;/P&gt;&lt;P&gt;Group by patient_id;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Create straight table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dimension:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;diagnosis &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;Expression:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;STRONG&gt;=sum(DISTINCT TotalCostPatientWise)/Count(DISTINCT total patient_id)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;STRONG&gt;&lt;IMG alt="Capture.JPG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/171293_Capture.JPG" style="height: auto;" /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 11:59:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358356#M824025</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2017-07-25T11:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358357#M824026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG alt="Capture.JPG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/171294_Capture.JPG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 12:01:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358357#M824026</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2017-07-25T12:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358358#M824027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Louise,&lt;/P&gt;&lt;P&gt;The expression I used&lt;/P&gt;&lt;P&gt;avg(Aggr(sum(total_cost),patient_id,diagnosis))&lt;/P&gt;&lt;P&gt;is equivalent to&lt;/P&gt;&lt;P&gt;avg(Aggr(sum(total_cost),[Episode Number]))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;because, if I understand correctly, each episode is a patient_id, diagnosis pair. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" style="font-size: 9pt;"&gt;&lt;TBODY&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TH bgcolor="#f5f5f5" nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;patient_id&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH bgcolor="#f5f5f5" nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;diagnosis&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH bgcolor="#f5f5f5" nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;Episode Number&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;sum(total_cost)&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;sum(total_cost)/count([Episode Number])&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="3"&gt;&lt;SPAN style="color: #363636;"&gt;12a&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1x&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah2&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2y&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;2000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="2"&gt;&lt;SPAN style="color: #363636;"&gt;13b&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;4z&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;3000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;3000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;3000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;3000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="4"&gt;&lt;SPAN style="color: #363636;"&gt;14c&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;5x&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah2&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;6z&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah3&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;9x&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;7500 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;2500 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="2"&gt;&lt;SPAN style="color: #363636;"&gt;15d&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;8y&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;13500 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1928.5714285714&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We can take out dimension Episode Number and get the same result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" style="font-size: 9pt;"&gt;&lt;TBODY&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TH bgcolor="#f5f5f5" nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;patient_id&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TH bgcolor="#f5f5f5" nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;diagnosis&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;sum(total_cost)&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;sum(total_cost)/count([Episode Number])&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="3"&gt;&lt;SPAN style="color: #363636;"&gt;12a&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah2&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;2000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="2"&gt;&lt;SPAN style="color: #363636;"&gt;13b&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;3000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;3000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;3000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;3000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="4"&gt;&lt;SPAN style="color: #363636;"&gt;14c&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah2&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah3&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;7500 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;2500 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff" rowspan="2"&gt;&lt;SPAN style="color: #363636;"&gt;15d&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;blah1&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1000 &lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt; &lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;13500 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1928.5714285714&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or have Episode Number only&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" style="font-size: 9pt;"&gt;&lt;TBODY&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TH bgcolor="#f5f5f5" nowrap="nowrap"&gt;&lt;SPAN style="color: #363636;"&gt;&lt;STRONG&gt;Episode Number&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/TH&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;sum(total_cost)&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;sum(total_cost)/count([Episode Number])&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1x&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2y&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;4z&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;3000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;3000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;5x&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;6z&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;8y&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;1000&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#ffffff"&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;9x&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD bgcolor="#ffffff"&gt;&lt;SPAN style="color: #363636;"&gt;2500&lt;/SPAN&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR bgcolor="#f5f5f5"&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;Total &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;13500 &lt;/STRONG&gt;&lt;/TD&gt;&lt;TD bgcolor="#f5f5f5"&gt;&lt;STRONG&gt;1928.5714285714&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 12:18:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358358#M824027</guid>
      <dc:creator>effinty2112</dc:creator>
      <dc:date>2017-07-25T12:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358359#M824028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Script:&lt;/P&gt;&lt;P&gt;Tab1:&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;patient_id, Episode Number, diagnosis, total_cost&lt;/P&gt;&lt;P&gt;12a, 1x, blah1, 1000&lt;/P&gt;&lt;P&gt;12a, 2y, blah2, 1000&lt;/P&gt;&lt;P&gt;13b, 4z, blah1, 3000&lt;/P&gt;&lt;P&gt;14c, 5x, blah1, 2500&lt;/P&gt;&lt;P&gt;14c, 6z, blah2, 2500&lt;/P&gt;&lt;P&gt;14c, 9x, blah3, 2500&lt;/P&gt;&lt;P&gt;15d, 8y, blah1, 1000&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;/P&gt;&lt;P&gt;LOAD patient_id,&lt;/P&gt;&lt;P&gt;Sum(total_cost) as NewCost&lt;/P&gt;&lt;P&gt;Resident Tab1&lt;/P&gt;&lt;P&gt;Group by patient_id&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;P&gt;Avg(NewCost)&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/171303_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 12:43:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358359#M824028</guid>
      <dc:creator>neelamsaroha157</dc:creator>
      <dc:date>2017-07-25T12:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358360#M824029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;or if you want original values at Episode level then you can change expression as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If(RowNo() =0, Avg(NewCost), Sum(total_cost))&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/171308_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jul 2017 12:50:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358360#M824029</guid>
      <dc:creator>neelamsaroha157</dc:creator>
      <dc:date>2017-07-25T12:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting unique values for aggregation - patient data</title>
      <link>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358361#M824030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to update - none of these ideas got me exactly what I needed, however they have provided me with couple of jump off points which have allowed me to combine a few ideas and get further than I was before. It looks like it can all be done via expressions and not involve load scripts and I am confident I can get it to work. For the moment I have to go do a Qlik Sense June 2017 server upgrade so I can't work on it now for a while. I will revert with the working expressions and close the question when I get back to it again. Many thanks for the insights and time, much appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Jul 2017 08:58:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Extracting-unique-values-for-aggregation-patient-data/m-p/1358361#M824030</guid>
      <dc:creator>betthisisnttake</dc:creator>
      <dc:date>2017-07-26T08:58:02Z</dc:date>
    </item>
  </channel>
</rss>

