<?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 combining 3 function (trim(subfield(replace in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262300#M1184087</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a field that needs to be extract in to 2 fields.&lt;/P&gt;&lt;P&gt; I've used &lt;STRONG&gt;subfield &lt;/STRONG&gt;function to extract 1 field into 2 fields 'country' and 'imex' then I used the &lt;STRONG&gt;trim &lt;/STRONG&gt;function to remove unnessary spaces within the field imex. Now I want to add the replace function to change some fieldvalues. My script now looks:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(trim(subfield(Fieldvalue, ',', 2)),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(replace(Fieldvalue,'A/','A'),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(replace(Fieldvalue, 'VL','V'),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(replace(Fieldvalue, 'EP', 'E'))))) as imex,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this is incorrect. I don't know how to combine these 3 function into one formula. if you combine multiple function, how do you know which one you should use first. In my case, should I start with: the replace function then the trim and subfield? or first the trim(subfield then the replace function?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope u can help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Isam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Oct 2011 09:02:29 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2011-10-20T09:02:29Z</dc:date>
    <item>
      <title>combining 3 function (trim(subfield(replace</title>
      <link>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262300#M1184087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a field that needs to be extract in to 2 fields.&lt;/P&gt;&lt;P&gt; I've used &lt;STRONG&gt;subfield &lt;/STRONG&gt;function to extract 1 field into 2 fields 'country' and 'imex' then I used the &lt;STRONG&gt;trim &lt;/STRONG&gt;function to remove unnessary spaces within the field imex. Now I want to add the replace function to change some fieldvalues. My script now looks:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(trim(subfield(Fieldvalue, ',', 2)),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(replace(Fieldvalue,'A/','A'),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(replace(Fieldvalue, 'VL','V'),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(replace(Fieldvalue, 'EP', 'E'))))) as imex,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this is incorrect. I don't know how to combine these 3 function into one formula. if you combine multiple function, how do you know which one you should use first. In my case, should I start with: the replace function then the trim and subfield? or first the trim(subfield then the replace function?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope u can help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Isam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 09:02:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262300#M1184087</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-10-20T09:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: combining 3 function (trim(subfield(replace</title>
      <link>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262301#M1184089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Isam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I may be wrong but I don't think you need so many If()s, rather than nesting Replace():&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"&gt;&lt;P&gt;Trim(Replace(Replace(Replace(SubField(Fieldvalue, ',', 2), 'A/', 'A'), 'VL', 'V'), 'EP', 'E')) AS imex&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.qlik.com/people/mabaeyens" style="font-size: 12px; outline-style: none; padding-top: 1px; padding-bottom: 1px; padding-left: 17px; color: #007fc0; zoom: 1; background-position: no-repeat no-repeat;"&gt;Miguel Angel Baeyens&lt;/A&gt;&lt;/P&gt;&lt;P&gt;BI Consultant&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="http://www.grupocomex.com/" style="font-size: 12px; outline-style: none; color: #007fc0;"&gt;Comex Grupo Ibérica&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 09:09:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262301#M1184089</guid>
      <dc:creator>Miguel_Angel_Baeyens</dc:creator>
      <dc:date>2011-10-20T09:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: combining 3 function (trim(subfield(replace</title>
      <link>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262302#M1184091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Miguel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THANKS A LOT!!!!! That worked!!! &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/grin.png" /&gt; Just curious how did you decide which function should be used first? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/grin.png" /&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;iSam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 09:33:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262302#M1184091</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-10-20T09:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: combining 3 function (trim(subfield(replace</title>
      <link>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262303#M1184093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Isam,&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;I'm not sure you need the if statements. As you have multiple scenarios where you are wishing to replace values, I would use the mapsubstring function and create a map with all the values you wish to replace.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The mapsubstring function then goes around the subfield and trim functions.&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"&gt;&lt;P&gt;Map:&lt;BR /&gt;Mapping LOAD * INLINE [&lt;BR /&gt;RemoveString, ReplaceString&lt;BR /&gt;A/,A&lt;BR /&gt;EP,E&lt;BR /&gt;VL,V&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;CountryImex&lt;BR /&gt;France;CA/L ;123&lt;BR /&gt;Germany;VLVATY;321&lt;BR /&gt;Spain; EPRAM;456&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;B:&lt;BR /&gt;LOAD&lt;BR /&gt;mapsubstring('Map',trim(subfield(CountryImex,';',2))) AS IMEX&lt;/P&gt;&lt;P&gt;RESIDENT A;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;James&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 09:33:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262303#M1184093</guid>
      <dc:creator />
      <dc:date>2011-10-20T09:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: combining 3 function (trim(subfield(replace</title>
      <link>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262304#M1184095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Isam,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First should be SubField(), since you need to get the value from the greater part. Second each of the replaces, then the Trim(). You can do the Trim() then the Replace(), but always first the SubField().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.qlik.com/people/mabaeyens" style="font-size: 12px; outline-style: none; padding-top: 1px; padding-bottom: 1px; padding-left: 17px; color: #007fc0; zoom: 1; background-position: no-repeat no-repeat;"&gt;Miguel Angel Baeyens&lt;/A&gt;&lt;/P&gt;&lt;P&gt;BI Consultant&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="http://www.grupocomex.com/" style="font-size: 12px; outline-style: none; color: #007fc0;"&gt;Comex Grupo Ibérica&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 09:35:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/combining-3-function-trim-subfield-replace/m-p/262304#M1184095</guid>
      <dc:creator>Miguel_Angel_Baeyens</dc:creator>
      <dc:date>2011-10-20T09:35:51Z</dc:date>
    </item>
  </channel>
</rss>

