<?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: Aggr function in script, change value of a field in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782465#M1020905</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the best solution depends a bit on your data and the actual logical reason for switching the value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the value switch is based on a statically incorrect value or some other predictable pattern, then I would consider using a mapping table to accomplish the value change. There are two great benefits to a mapping table; it is easy to maintain and it is efficient in execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example a possible implementation could be like below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_1427257125017260" jivemacro_uid="_1427257125017260" modifiedtitle="true"&gt;
&lt;P&gt;MapAnimal:&lt;/P&gt;
&lt;P&gt;Mapping LOAD * Inline [&lt;/P&gt;
&lt;P&gt;Key , Animal&lt;/P&gt;
&lt;P&gt;1cat , dog&lt;/P&gt;
&lt;P&gt;2cat , horse&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;T1:&lt;/P&gt;
&lt;P&gt;LOAD &lt;/P&gt;
&lt;P&gt;&amp;nbsp; Id,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ApplyMap('MapAnimal', Id&amp;amp;Animal, Animal) AS Animal&lt;/P&gt;
&lt;P&gt;Inline [Id, Animal&lt;/P&gt;
&lt;P&gt;1,dog&lt;/P&gt;
&lt;P&gt;1,dog&lt;/P&gt;
&lt;P&gt;1,cat&lt;/P&gt;
&lt;P&gt;2,horse&lt;/P&gt;
&lt;P&gt;2,horse&lt;/P&gt;
&lt;P&gt;2,cat&lt;/P&gt;
&lt;P&gt;3,parrot&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Mar 2015 04:21:40 GMT</pubDate>
    <dc:creator>ToniKautto</dc:creator>
    <dc:date>2015-03-25T04:21:40Z</dc:date>
    <item>
      <title>Aggr function in script, change value of a field</title>
      <link>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782462#M1020902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have a little problem in script. I have to change a value in a field. The table looks like this:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Value&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;dog&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;dog&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;cat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;horse&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;horse&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;cat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;parrot&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So what i have to do is to sign one value to ID. So firstly i have to check if Aggr(Count(DISTIINCT Value, ID) is &amp;gt;0 if yes, i have to change the "cat" for ID 1 to "dog", thesame operation in ID 2. How can i do that ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jacek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Mar 2015 16:17:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782462#M1020902</guid>
      <dc:creator />
      <dc:date>2015-03-24T16:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Aggr function in script, change value of a field</title>
      <link>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782463#M1020903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jacek,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what you can do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[Data_temp]:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RecNo() as Recordnr&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID, &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;From YOURDATAFILE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;[Data]:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;LOAD &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(ID=Peek(ID,-1),Peek(Value,-1),Value)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as Value,&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;RESIDENT Data_temp &lt;/SPAN&gt;ORDER BY &lt;SPAN style="font-size: 13.3333330154419px;"&gt;Recordnr&lt;/SPAN&gt; ASC;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;drop table Data_temp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;drop field Recordnr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Kind Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Jop&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Mar 2015 16:30:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782463#M1020903</guid>
      <dc:creator>jopmoekotte</dc:creator>
      <dc:date>2015-03-24T16:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Aggr function in script, change value of a field</title>
      <link>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782464#M1020904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use a where not exists clause like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD * Inline [Id, Animal&lt;/P&gt;&lt;P&gt;1,dog&lt;/P&gt;&lt;P&gt;1,dog&lt;/P&gt;&lt;P&gt;1,cat&lt;/P&gt;&lt;P&gt;2,horse&lt;/P&gt;&lt;P&gt;2,horse&lt;/P&gt;&lt;P&gt;2,cat&lt;/P&gt;&lt;P&gt;3,parrot&lt;/P&gt;&lt;P&gt;] Where not Exists(Id);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Mar 2015 17:33:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782464#M1020904</guid>
      <dc:creator>stigchel</dc:creator>
      <dc:date>2015-03-24T17:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Aggr function in script, change value of a field</title>
      <link>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782465#M1020905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the best solution depends a bit on your data and the actual logical reason for switching the value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the value switch is based on a statically incorrect value or some other predictable pattern, then I would consider using a mapping table to accomplish the value change. There are two great benefits to a mapping table; it is easy to maintain and it is efficient in execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this example a possible implementation could be like below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_1427257125017260" jivemacro_uid="_1427257125017260" modifiedtitle="true"&gt;
&lt;P&gt;MapAnimal:&lt;/P&gt;
&lt;P&gt;Mapping LOAD * Inline [&lt;/P&gt;
&lt;P&gt;Key , Animal&lt;/P&gt;
&lt;P&gt;1cat , dog&lt;/P&gt;
&lt;P&gt;2cat , horse&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;T1:&lt;/P&gt;
&lt;P&gt;LOAD &lt;/P&gt;
&lt;P&gt;&amp;nbsp; Id,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ApplyMap('MapAnimal', Id&amp;amp;Animal, Animal) AS Animal&lt;/P&gt;
&lt;P&gt;Inline [Id, Animal&lt;/P&gt;
&lt;P&gt;1,dog&lt;/P&gt;
&lt;P&gt;1,dog&lt;/P&gt;
&lt;P&gt;1,cat&lt;/P&gt;
&lt;P&gt;2,horse&lt;/P&gt;
&lt;P&gt;2,horse&lt;/P&gt;
&lt;P&gt;2,cat&lt;/P&gt;
&lt;P&gt;3,parrot&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2015 04:21:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Aggr-function-in-script-change-value-of-a-field/m-p/782465#M1020905</guid>
      <dc:creator>ToniKautto</dc:creator>
      <dc:date>2015-03-25T04:21:40Z</dc:date>
    </item>
  </channel>
</rss>

