<?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 Separating keys from data in one table in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206175#M62395</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks both for your input. The sample qlikview file looks great!&lt;/P&gt;&lt;P&gt;I've a little trouble understanding the logic. Can you explain in plain english what the code below does?&lt;/P&gt;&lt;P&gt;LEFT JOIN (C)&lt;BR /&gt;LOAD&lt;BR /&gt; Sequence&lt;BR /&gt;,Field1&lt;BR /&gt;,if(exists(Field2,Field1),Field1,peek(Field2)) as Field2&lt;BR /&gt;RESIDENT C&lt;BR /&gt;ORDER BY Sequence DESC&lt;BR /&gt;;&lt;BR /&gt;INNER JOIN (C)&lt;BR /&gt;LOAD Sequence&lt;BR /&gt;RESIDENT C&lt;BR /&gt;WHERE Field1&amp;lt;&amp;gt;Field2&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 Sep 2010 12:49:18 GMT</pubDate>
    <dc:creator />
    <dc:date>2010-09-17T12:49:18Z</dc:date>
    <item>
      <title>Separating keys from data in one table</title>
      <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206172#M62392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear QV-gurus,&lt;/P&gt;&lt;P&gt;My datasource is a table consisting of one column which for example contains the following data&lt;/P&gt;&lt;P&gt;abcd&lt;/P&gt;&lt;P&gt;bcde&lt;/P&gt;&lt;P&gt;cdef&lt;/P&gt;&lt;P&gt;0001&lt;/P&gt;&lt;P&gt;defg&lt;/P&gt;&lt;P&gt;efgh&lt;/P&gt;&lt;P&gt;fghi&lt;/P&gt;&lt;P&gt;0002&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THe numeric values are the keys for the textvalues above it. The data needs to be transformed so that it outputs the following:&lt;/P&gt;&lt;P&gt;0001 abcd&lt;/P&gt;&lt;P&gt;0001 bcde&lt;/P&gt;&lt;P&gt;0001 cdef&lt;/P&gt;&lt;P&gt;0002 defg&lt;/P&gt;&lt;P&gt;0002 efgh&lt;/P&gt;&lt;P&gt;0002 fghi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I go about this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Sep 2010 10:32:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206172#M62392</guid>
      <dc:creator />
      <dc:date>2010-09-17T10:32:33Z</dc:date>
    </item>
    <item>
      <title>Separating keys from data in one table</title>
      <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206173#M62393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi karuna can you reffered this qv file. It will help you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Sep 2010 11:36:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206173#M62393</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-09-17T11:36:52Z</dc:date>
    </item>
    <item>
      <title>Separating keys from data in one table</title>
      <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206174#M62394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Karuna,&lt;/P&gt;&lt;P&gt;Logic for achieving this should be as follow,&lt;/P&gt;&lt;P&gt;Step 1:&lt;/P&gt;&lt;P&gt;Segeregate your data column into two different column like one would be numeric and another one would be text. your code should be some thing similar as below&lt;/P&gt;&lt;P&gt;if( len(purgechar(Field,'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) &amp;gt;0,Field) as Numeric_Field,&lt;BR /&gt;if( len(purgechar(Field,'1234567890')) &amp;gt;0,Field) as String_Field,&lt;/P&gt;&lt;P&gt;Your data will look like this&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Numeric_Field String_Field&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;- abcd&lt;/P&gt;&lt;P&gt;- bcde&lt;/P&gt;&lt;P&gt;- cdef&lt;/P&gt;&lt;P&gt;001 -&lt;/P&gt;&lt;P&gt;- defg&lt;/P&gt;&lt;P&gt;- efgh&lt;/P&gt;&lt;P&gt;- f ghi&lt;BR /&gt;0002 -&lt;/P&gt;&lt;P&gt;Once you get the data in this format.&lt;/P&gt;&lt;P&gt;Step 2:&lt;/P&gt;&lt;P&gt;Fill your missing data in Numeric_Field with peek() function.&lt;/P&gt;&lt;P&gt;Once you do this you will get you required format.&lt;/P&gt;&lt;P&gt;I dnt have QV installed in my system now with me, so i cant send you a sample app.&lt;/P&gt;&lt;P&gt;Try this above step, u`ll get the desired result.&lt;/P&gt;&lt;P&gt;Hope this will help you&lt;/P&gt;&lt;P&gt;-Sridhar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Sep 2010 11:37:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206174#M62394</guid>
      <dc:creator />
      <dc:date>2010-09-17T11:37:33Z</dc:date>
    </item>
    <item>
      <title>Separating keys from data in one table</title>
      <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206175#M62395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks both for your input. The sample qlikview file looks great!&lt;/P&gt;&lt;P&gt;I've a little trouble understanding the logic. Can you explain in plain english what the code below does?&lt;/P&gt;&lt;P&gt;LEFT JOIN (C)&lt;BR /&gt;LOAD&lt;BR /&gt; Sequence&lt;BR /&gt;,Field1&lt;BR /&gt;,if(exists(Field2,Field1),Field1,peek(Field2)) as Field2&lt;BR /&gt;RESIDENT C&lt;BR /&gt;ORDER BY Sequence DESC&lt;BR /&gt;;&lt;BR /&gt;INNER JOIN (C)&lt;BR /&gt;LOAD Sequence&lt;BR /&gt;RESIDENT C&lt;BR /&gt;WHERE Field1&amp;lt;&amp;gt;Field2&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Sep 2010 12:49:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206175#M62395</guid>
      <dc:creator />
      <dc:date>2010-09-17T12:49:18Z</dc:date>
    </item>
    <item>
      <title>Separating keys from data in one table</title>
      <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206176#M62396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi karuna. You go to the edit script-&amp;gt;debug.there you will get the steps, please refer..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Sep 2010 13:21:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206176#M62396</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-09-17T13:21:11Z</dc:date>
    </item>
    <item>
      <title>Separating keys from data in one table</title>
      <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206177#M62397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="jive_text_macro jive_macro_quote" jivemacro="quote"&gt;&lt;BR /&gt;karuna wrote: The sample qlikview file looks great!&lt;BR /&gt;I've a little trouble understanding the logic. Can you explain in plain english what the code below does?&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Well, that's from the script I wrote when somone asked the exact same question in the below thread three days ago. Are you both working on the same project? Is this some sample exercise given in a QlikView class? I'm just curious why it's being asked twice in the space of three days.&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;&lt;A href="http://community.qlik.com/forums/t/34049.aspx"&gt;http://community.qlik.com/forums/t/34049.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Anyway, at the point in the script that you're asking about, table C looks like this:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;Sequence, Field1&lt;BR /&gt;1,abcd&lt;BR /&gt;2,bcde&lt;BR /&gt;3,cdef&lt;BR /&gt;4,0001&lt;BR /&gt;5,defg&lt;BR /&gt;6,efgh&lt;BR /&gt;7,fghi&lt;BR /&gt;8,0002&lt;/P&gt;&lt;P&gt;And we also have a table B:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;Field2&lt;BR /&gt;0001&lt;BR /&gt;0002&lt;/P&gt;&lt;P&gt;And now we do this join:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;LEFT JOIN (C)&lt;BR /&gt;LOAD&lt;BR /&gt; Sequence&lt;BR /&gt;,Field1 // This field isn't necessary and can be removed&lt;BR /&gt;,if(exists(Field2,Field1),Field1,peek(Field2)) as Field2&lt;BR /&gt;RESIDENT C&lt;BR /&gt;ORDER BY Sequence DESC&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;The join is being done from C back onto itself on both Sequence and Field1. Field1 can be removed since the record is already uniquely identified by Sequence. I didn't catch that when I first wrote this. Then we're adding a Field2 to C, defined like this:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;,if(exists(Field2,Field1),Field1,peek(Field2)) as Field2&lt;/P&gt;&lt;P&gt;This says, "If the value of Field1 is an existing value of Field2 (i.e., either 0001 or 0002), then use Field 1. If it isn't (i.e., one of the alphabetic strings), then look at the row above this one in table C, and grab the value of Field2 from it instead." Applying that to our table C, and keeping in mind that we ordered by sequence DESCENDING:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;Sequence, Field1, Field2&lt;BR /&gt;8,0002,0002 &amp;lt;-- 0002 is an existing Field2 value, so we use it&lt;BR /&gt;7,fghi,0002 &amp;lt;-- fghi isn't an existing Field2 value, so we look at the previous row (sequence &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; and grab Field2 from there&lt;BR /&gt;6,efgh,0002 &amp;lt;-- efgh isn't an existing Field2 value, so we look at the previous row (sequence 7) and grab Field2 from there&lt;BR /&gt;etc.&lt;/P&gt;&lt;P&gt;Next we do this join:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;INNER JOIN (C)&lt;BR /&gt;LOAD Sequence&lt;BR /&gt;RESIDENT C&lt;BR /&gt;WHERE Field1&amp;lt;&amp;gt;Field2&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;An inner join says to only keep rows from table C that ALSO exist in what we're loading in our load statement. What we're loading in our load statement are only those rows from table C where Field1 is not the same as Field2. So what this says is to DELETE any rows in table C where Field1 EQUALS Field2. Those are the rows with the numeric codes in Field1. So the inner join will delete all rows with a numeric code in Field1. Now, I could have just checked if Field1 was numeric, but I was trying to assume that the code values we're applying might not always be numeric, but would instead be identified by a separate load (table B).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 Sep 2010 00:05:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206177#M62397</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2010-09-18T00:05:22Z</dc:date>
    </item>
    <item>
      <title>Separating keys from data in one table</title>
      <link>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206178#M62398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;John,&lt;/P&gt;&lt;P&gt;As far as I know this is not part of some certifcation process &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you kindly for the thorough explanation and text. This really helps alot to understand the code used to generate the correct outcome for this problem.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;//kAruna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Sep 2010 07:08:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Separating-keys-from-data-in-one-table/m-p/206178#M62398</guid>
      <dc:creator />
      <dc:date>2010-09-23T07:08:59Z</dc:date>
    </item>
  </channel>
</rss>

