<?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: Bad performance using variable to calculate field in Connectivity &amp; Data Prep</title>
    <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154758#M13151</link>
    <description>&lt;P&gt;Setting Verbatim to 1 solved the problem! Didn't have a clue about this system variable. Thanks for the tip&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 17:06:31 GMT</pubDate>
    <dc:creator>pedrohenriqueperna</dc:creator>
    <dc:date>2023-12-19T17:06:31Z</dc:date>
    <item>
      <title>Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154312#M13129</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm doing some extense transformation in customer data and at some point I compare address strings looking for typing errors. Things were working fine before my last step that involves using a big nested Replace() expression, along with some SubStringCount() and SubField().&lt;/P&gt;
&lt;P&gt;Basically, instead of repeating this big expression I added it to a SET variable and surprisingly it works, but only if I calculate the variable without single quotes -&amp;gt; $(vExample) as MyField instead of '$(vExample)' as MyField.&lt;/P&gt;
&lt;P&gt;The problem is that loading is now taking too long, and the weird thing about it is that I only use this in a first table load that prepares the data to a nested loop sequence, but it affects directly the rest of the script.&lt;/P&gt;
&lt;P&gt;Why is this happening? The table with the variable as a field is already loaded and it loaded fast. Is it because I'm using the values from the table and it somehow recalculates everytime?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 01:34:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154312#M13129</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-19T01:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154313#M13130</link>
      <description>&lt;P&gt;SET vReplaceRuaODS = If(IsNum(SubField(&lt;/P&gt;
&lt;P&gt;$(vReplaceFunc)Upper(cliente_rua_temp),&lt;BR /&gt;$(vReplaceStr), ' ', SubStringCount(&lt;/P&gt;
&lt;P&gt;$(vReplaceFunc)Upper(cliente_rua_temp),&lt;BR /&gt;$(vReplaceStr), ' ') + 1)), Trim(PurgeChar(&lt;/P&gt;
&lt;P&gt;$(vReplaceFunc)Upper(cliente_rua_temp),&lt;BR /&gt;$(vReplaceStr), '1234567890')),&lt;/P&gt;
&lt;P&gt;Trim($(vReplaceFunc)Upper(cliente_rua_temp),&lt;BR /&gt;$(vReplaceStr)));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the variable holding the expression as text&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 01:39:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154313#M13130</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-19T01:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154480#M13138</link>
      <description>&lt;P&gt;Your variable contained itself variables which is technically possible but not always trivial or expedient (if the complexity increased more as it simplified the matter). Beside this looked the call of:&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;SubField(&lt;STRONG&gt;$(vReplaceFunc)&lt;/STRONG&gt;Upper(cliente_rua_temp),&lt;BR /&gt;...&lt;/P&gt;
&lt;P&gt;within the outer-variable not correct because the variable here is isolated ...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an alternatively for multiple (nested) replace-statement you may apply a mapsubstring().&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 10:08:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154480#M13138</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2023-12-19T10:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154636#M13142</link>
      <description>&lt;P&gt;I've looked into mapsubstring() but the example in qlik help got me a bit confused.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Considering the following nested replace expression, can you give me an example of how it would work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace(Replace(Replace(Replace(customer_address, 'Avenida ', ''), 'Estrada ', ''), 'Rodovia ', ''), 'Alameda ', '');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case I'm trying to remove these substrings (ex. avenida, estrada..) and replacing it for nothing. I ended up using replace because I can get the whole substring with a subsequent space ('Avenida ') to make sure to replace only if it's the first substring inside the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for what you said about the variable being isolated, I'm not sure if I understood it right, but if it's about having the Upper(..) right beside the variable, it's because I added the nested Replace(Replace(Replace( to the vReplaceFunc, and the to be replaced strings (ex. 'Avenida ', 'Estrada '...) to the vReplaceStr. Finally, to avoid having a different variable to each field I need to replace I used Upper(field) between the variables. I know it's messy, but it does work. Unfortunately it affects the performance of the script overall&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 13:39:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154636#M13142</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-19T13:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154651#M13144</link>
      <description>&lt;P&gt;The mapsubstring() might be applied like:&lt;/P&gt;
&lt;P&gt;m: mapping load * inline [&lt;BR /&gt;Lookup, Return&lt;BR /&gt;&lt;SPAN&gt;"Avenida ", ""&lt;BR /&gt;"Estrada ", ""&lt;BR /&gt;"Rodovia ", ""&lt;BR /&gt;"Alameda ", ""];&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;t: load *, mapsubstring('m', YourField) as YourFieldAdjusted&lt;BR /&gt;resident X;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Considering spaces within an inline-load is sometimes a bit tricky but mostly a wrapping with quotes will do the job. Alternatively the verbatim-variable might be adjusted. But nearly always it will be to load such data from an external source which will also enable other users to add/remove/change mapping-values which have no access to the script.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Each kind of wrong typing could be added to the mapping and the mappings might be also hierarchically nested like:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;mapsubstring('m2', mapsubstring('m1', YourField))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In regard to your variable must be something quite wrong because a variable means mainly that the hard-coded content is shortened to the variable-name and resolved again by the call which means there is no difference between them - results and run-times must be the same. If not - it means that the variable has another content.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 14:12:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154651#M13144</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2023-12-19T14:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154661#M13146</link>
      <description>&lt;P&gt;Marcus, it seems to be working perfectly. Thank you very much for the tip. As for the processing it's back to normal, so the problem was indeed the variable I was using. It's really weird, because of what I said. The variable is not being used at all after the first table loaded (that loads quite fast). To make sure, I set the same variables to Null right after the table is loaded, and for some reason it jams the whole script.&lt;/P&gt;
&lt;P&gt;I guess it must be something related to how I nested the variables and text, but it doesn't matter anymore as it's working now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 14:32:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154661#M13146</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-19T14:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154697#M13148</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/28038"&gt;@marcus_sommer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Marcus, I just got a case that the space is not being considered &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this table for the mapping&lt;/P&gt;
&lt;P&gt;ReplaceMap:&lt;/P&gt;
&lt;P&gt;LOAD * Inline [&lt;/P&gt;
&lt;P&gt;A, B&lt;/P&gt;
&lt;P&gt;"AVENIDA ",&lt;/P&gt;
&lt;P&gt;"ESTRADA ",&lt;/P&gt;
&lt;P&gt;"DR ",&lt;/P&gt;
&lt;P&gt;[...]&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;And have this string: AVENIDA DA PEDRA BRANCA&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output is giving me: DA PEA BRANCA (it's removing DR from withing PEDRA)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas how to make it consider the space?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 15:29:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154697#M13148</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-19T15:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154708#M13149</link>
      <description>&lt;P&gt;Just try it with:&amp;nbsp;&lt;A href="https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/SystemVariables/Verbatim.htm" target="_blank"&gt;Verbatim | Qlik Cloud Help&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 15:50:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154708#M13149</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2023-12-19T15:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154758#M13151</link>
      <description>&lt;P&gt;Setting Verbatim to 1 solved the problem! Didn't have a clue about this system variable. Thanks for the tip&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 17:06:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2154758#M13151</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-19T17:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2155199#M13162</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/28038"&gt;@marcus_sommer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi, marcus&lt;/P&gt;
&lt;P&gt;I'm almost done dealing with special cases, but one. I'm hoping you could help me again.&lt;/P&gt;
&lt;P&gt;Part of the script routine involves eliminating prepositions and addresses terms like "of, from, to..." and "street, avenue..." to compare 2 strings.&lt;/P&gt;
&lt;P&gt;Setting the verbatim to 1 helped me to compare strings using spaces as delimiter, but there are some very special cases that a address string starts with a preposition and have no leading spaces, e.g:&lt;/P&gt;
&lt;P&gt;AVENIDA DAS FLORES = Normal string, where "DAS" is a preposition that will be removed with mapsubstring searching for " DAS " and "AVENIDA" will be removed searching for "AVENIDA ".&lt;/P&gt;
&lt;P&gt;DAS FLORES = Special string where "AVENIDA" is already not present, but in this case I have a "DAS " substring that will not be mapped with " DAS ". If I add "DAS " to the table map it will remove every substring that ends with "DAS " as well (e.g "LINDAS " will be replaced to "LIN").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what I thought I could do is simple concatenate a space before the string, something like: ' '&amp;amp;'DAS FLORES'. This way mapsubstring would still read " DAS " and proceed with the replacement, but for some reason it doesn't work when adding the space inside the SET variable text:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SET vReplaceRuaODS = If(IsNum(SubField(cliente_rua_temp, ' ', SubStringCount(cliente_rua_temp, ' ') + 1))&lt;BR /&gt;and Not(Exists(TermosEndereco, SubField(Upper(cliente_rua_temp), ' ', SubStringCount(cliente_rua_temp, ' '))))&lt;BR /&gt;and SubStringCount(cliente_rua_temp, ' ') &amp;gt; 0, &lt;BR /&gt;Trim(PurgeChar(MapSubString('ReplaceMap', MapSubString('ReplaceMap', Upper(cliente_rua_temp))), '1234567890')), &lt;BR /&gt;If(Exists(PreposicaoEndereco, SubField(Upper(cliente_rua_temp), ' ', 1)), &lt;BR /&gt;Trim(MapSubString('ReplaceMap', MapSubString('ReplaceMap', &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;' '&amp;amp;&lt;/FONT&gt;&lt;/STRONG&gt;Upper(cliente_rua_temp)))),&lt;BR /&gt;Trim(MapSubString('ReplaceMap', MapSubString('ReplaceMap', Upper(cliente_rua_temp))))));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried adding the string as inline with a space just for testing and it works, but it won't work when I add the space in the text for the variable. I also tried using Chr(32) and Chr(160), but with no sucess.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This must be simple. Do you have any clue how to achieve this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 19:26:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2155199#M13162</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-20T19:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2155400#M13165</link>
      <description>&lt;P&gt;In general the approach should work. Noticeable is that there are no spaces between the concat-parts which prevents in some scenarios the intended parsing. Therefore you could try it like:&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;' ' &amp;amp;&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;SPAN&gt;Upper(clie&lt;/SPAN&gt;&lt;SPAN&gt;nte_rua_temp)&lt;/SPAN&gt; ...&lt;/P&gt;
&lt;P&gt;or alternatively:&lt;/P&gt;
&lt;P&gt;...&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Upper(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;' ' &amp;amp;&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;clie&lt;/SPAN&gt;&lt;SPAN&gt;nte_rua_temp)&lt;/SPAN&gt; ...&lt;/P&gt;
&lt;P&gt;Beside this is each replace-approach difficult to (practically) impossible if there is any overlapping between the replace-substrings and/or their position and frequency is not unique&amp;nbsp;definable. Some tasks are solvable by applying the replace in multiple steps which are hierarchically ordered and are only applied on certain substrings.&lt;/P&gt;
&lt;P&gt;But in more complex scenarios I would tend not to try to clean the entire string at ones else separating each sub-string per subfield(), maybe like:&lt;/P&gt;
&lt;P&gt;load *, len/isnum/istext(Substring) as ...;&lt;BR /&gt;load *, subfield(String, ' ', iterno()) as Substring, recno() as RecNo, iterno() as IterNo&lt;BR /&gt;from Source while iterno() &amp;lt;= substringcount(String, ' ');&lt;/P&gt;
&lt;P&gt;With the&amp;nbsp;len/isnum/istext() + similar checks and IterNo the content of each substring could be identified and on it afterwards specialized replace/cleaning-logic applied. The final step would be to concatenate the substrings again to the complete string with the help of RecNo and IterNo.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 10:54:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2155400#M13165</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2023-12-21T10:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Bad performance using variable to calculate field</title>
      <link>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2155461#M13167</link>
      <description>&lt;P&gt;Hi, marcus. Thanks for the reply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It turns out to be something else that I was doing wrong. Using ' '&amp;amp;Upper(cliente_rua_temp) did the job after fixing it.&lt;/P&gt;
&lt;P&gt;Still what you said is interesting, about separating the substrings. I actually do this at some part of the script, but this approach seems to be more efficient, I'll definitely try it and compare the results.&lt;/P&gt;
&lt;P&gt;Thanks again!!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 13:21:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Connectivity-Data-Prep/Bad-performance-using-variable-to-calculate-field/m-p/2155461#M13167</guid>
      <dc:creator>pedrohenriqueperna</dc:creator>
      <dc:date>2023-12-21T13:21:36Z</dc:date>
    </item>
  </channel>
</rss>

