<?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 Peek() with multiple values in Order By in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Peek-with-multiple-values-in-Order-By/m-p/19722#M3247</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to find the test Result for the Specimen that was Collected closest to but not after a blood TransfusionDateTime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Patients can have multiple SpecimenCollectionDateTimes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SpecimenCollectionDateTimes can have multiple Tests.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TransfusionDateTimes can have multiple blood Units.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;We want to track Test Results for each blood Unit &lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;not for each TransfusionDateTime).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've calculated the [Hours Difference] between each TransfusionDateTime and each SpecimenCollectionDateTime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And using Peek and Order By, I've told it to add a count to the SpecimenCollectionDateTime starting with "-1" for the last one before the transfusion and subtracting 1 for each prior but it doesn't always work (I also attached a .qvw):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TempTestTimes:&lt;/P&gt;&lt;P&gt;LOAD [Account Number] as TempAccountNumber&lt;/P&gt;&lt;P&gt;,[Transfusion DTTM] as TempTransfusionDTTM&lt;/P&gt;&lt;P&gt;Resident TransfusedUnits;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JOIN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD [Account Number] as TempAccountNumber&lt;/P&gt;&lt;P&gt;,[TestName] as TempTestName&lt;/P&gt;&lt;P&gt;,[Specimen Collection DTTM] as TempSpecCollectionDTTM&lt;/P&gt;&lt;P&gt;,[Test Result] as TempTestResult&lt;/P&gt;&lt;P&gt;Resident LabData;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TempTestTimeDifferences:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;RecNo() as TempRecNo,&lt;/P&gt;&lt;P&gt;TempAccountNumber,&lt;/P&gt;&lt;P&gt;TempTransfusionDTTM,&lt;/P&gt;&lt;P&gt;TempTestName,&lt;/P&gt;&lt;P&gt;TempSpecCollectionDTTM,&lt;/P&gt;&lt;P&gt;INTERVAL(TempSpecCollectionDTTM - TempTransfusionDTTM, 'hh:mm') as [Hours Difference]&lt;/P&gt;&lt;P&gt;,TempTestResult&lt;/P&gt;&lt;P&gt;Resident TempTestTimes&lt;/P&gt;&lt;P&gt;WHERE TempSpecCollectionDTTM &amp;lt; TempTransfusionDTTM&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JOIN (TempTestTimeDifferences)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD TempRecNo&lt;/P&gt;&lt;P&gt;,If(&lt;/P&gt;&lt;P&gt;(TempAccountNumber = previous(TempAccountNumber)&lt;/P&gt;&lt;P&gt;AND TempTransfusionDTTM = previous(TempTransfusionDTTM)&lt;/P&gt;&lt;P&gt;AND TempSpecCollectionDTTM = previous(TempSpecCollectionDTTM)&lt;/P&gt;&lt;P&gt;AND&amp;nbsp; TempTestName = previous(TempTestName)&lt;/P&gt;&lt;P&gt;AND [Hours Difference] = previous([Hours Difference])&lt;/P&gt;&lt;P&gt;AND [Hours Difference] &amp;lt; 0&lt;/P&gt;&lt;P&gt;), peek([Hours Difference Rank])-1,-1) as [Hours Difference Rank]&lt;/P&gt;&lt;P&gt;Resident TempTestTimeDifferences&lt;/P&gt;&lt;P&gt;//Where [Hours Difference] &amp;lt; 0&lt;/P&gt;&lt;P&gt;Order By TempAccountNumber, TempTransfusionDTTM, TempSpecCollectionDTTM, TempTestName,UnitNumber,&lt;/P&gt;&lt;P&gt;[Hours Difference] desc&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One scenario that proved difficult was when some blood tests (Hemoglobin, Platelets, INR) were done on multiple specimens (each with their own SpecimenCollectionDateTime) and some were only done on one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Feb 2018 18:05:44 GMT</pubDate>
    <dc:creator>Margaret</dc:creator>
    <dc:date>2018-02-13T18:05:44Z</dc:date>
    <item>
      <title>Peek() with multiple values in Order By</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-with-multiple-values-in-Order-By/m-p/19722#M3247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to find the test Result for the Specimen that was Collected closest to but not after a blood TransfusionDateTime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Patients can have multiple SpecimenCollectionDateTimes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SpecimenCollectionDateTimes can have multiple Tests.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TransfusionDateTimes can have multiple blood Units.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;We want to track Test Results for each blood Unit &lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;not for each TransfusionDateTime).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've calculated the [Hours Difference] between each TransfusionDateTime and each SpecimenCollectionDateTime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And using Peek and Order By, I've told it to add a count to the SpecimenCollectionDateTime starting with "-1" for the last one before the transfusion and subtracting 1 for each prior but it doesn't always work (I also attached a .qvw):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TempTestTimes:&lt;/P&gt;&lt;P&gt;LOAD [Account Number] as TempAccountNumber&lt;/P&gt;&lt;P&gt;,[Transfusion DTTM] as TempTransfusionDTTM&lt;/P&gt;&lt;P&gt;Resident TransfusedUnits;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JOIN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD [Account Number] as TempAccountNumber&lt;/P&gt;&lt;P&gt;,[TestName] as TempTestName&lt;/P&gt;&lt;P&gt;,[Specimen Collection DTTM] as TempSpecCollectionDTTM&lt;/P&gt;&lt;P&gt;,[Test Result] as TempTestResult&lt;/P&gt;&lt;P&gt;Resident LabData;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TempTestTimeDifferences:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;RecNo() as TempRecNo,&lt;/P&gt;&lt;P&gt;TempAccountNumber,&lt;/P&gt;&lt;P&gt;TempTransfusionDTTM,&lt;/P&gt;&lt;P&gt;TempTestName,&lt;/P&gt;&lt;P&gt;TempSpecCollectionDTTM,&lt;/P&gt;&lt;P&gt;INTERVAL(TempSpecCollectionDTTM - TempTransfusionDTTM, 'hh:mm') as [Hours Difference]&lt;/P&gt;&lt;P&gt;,TempTestResult&lt;/P&gt;&lt;P&gt;Resident TempTestTimes&lt;/P&gt;&lt;P&gt;WHERE TempSpecCollectionDTTM &amp;lt; TempTransfusionDTTM&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;JOIN (TempTestTimeDifferences)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD TempRecNo&lt;/P&gt;&lt;P&gt;,If(&lt;/P&gt;&lt;P&gt;(TempAccountNumber = previous(TempAccountNumber)&lt;/P&gt;&lt;P&gt;AND TempTransfusionDTTM = previous(TempTransfusionDTTM)&lt;/P&gt;&lt;P&gt;AND TempSpecCollectionDTTM = previous(TempSpecCollectionDTTM)&lt;/P&gt;&lt;P&gt;AND&amp;nbsp; TempTestName = previous(TempTestName)&lt;/P&gt;&lt;P&gt;AND [Hours Difference] = previous([Hours Difference])&lt;/P&gt;&lt;P&gt;AND [Hours Difference] &amp;lt; 0&lt;/P&gt;&lt;P&gt;), peek([Hours Difference Rank])-1,-1) as [Hours Difference Rank]&lt;/P&gt;&lt;P&gt;Resident TempTestTimeDifferences&lt;/P&gt;&lt;P&gt;//Where [Hours Difference] &amp;lt; 0&lt;/P&gt;&lt;P&gt;Order By TempAccountNumber, TempTransfusionDTTM, TempSpecCollectionDTTM, TempTestName,UnitNumber,&lt;/P&gt;&lt;P&gt;[Hours Difference] desc&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One scenario that proved difficult was when some blood tests (Hemoglobin, Platelets, INR) were done on multiple specimens (each with their own SpecimenCollectionDateTime) and some were only done on one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Feb 2018 18:05:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-with-multiple-values-in-Order-By/m-p/19722#M3247</guid>
      <dc:creator>Margaret</dc:creator>
      <dc:date>2018-02-13T18:05:44Z</dc:date>
    </item>
  </channel>
</rss>

