<?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 Field calculator Script for merging fields with conditions. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663449#M51551</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need help with writing VBA or python script that will merge fields&amp;nbsp;in way I did it in excel (see formula&amp;nbsp;applied on red column in attached spreadsheet).&lt;/P&gt;&lt;P&gt;Basically merging fields but with some conditions implemented.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Apr 2019 16:42:06 GMT</pubDate>
    <dc:creator>VukCeperkovic1</dc:creator>
    <dc:date>2019-04-10T16:42:06Z</dc:date>
    <item>
      <title>Field calculator Script for merging fields with conditions.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663449#M51551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need help with writing VBA or python script that will merge fields&amp;nbsp;in way I did it in excel (see formula&amp;nbsp;applied on red column in attached spreadsheet).&lt;/P&gt;&lt;P&gt;Basically merging fields but with some conditions implemented.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2019 16:42:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663449#M51551</guid>
      <dc:creator>VukCeperkovic1</dc:creator>
      <dc:date>2019-04-10T16:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator Script for merging fields with conditions.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663450#M51552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;security toasted your vba macro I presume.&amp;nbsp; So just in case you needed to check for nulls, here is the principle behind it.&amp;nbsp; It will produce a concatenated text string for three fields&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;conc&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; c&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    vals &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; c&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
    txt &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"{}{}{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; c&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; txt



conc&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1000&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'a'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
Out&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;19&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'1000Nonea'&lt;/SPAN&gt;

conc&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1000&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'a'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
Out&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;20&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'1000a5'&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:02:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663450#M51552</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T04:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator Script for merging fields with conditions.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663451#M51553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try the following expression using the Python parser:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{}0{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!odeljenje!&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;!odesk!&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Apr 2019 21:04:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663451#M51553</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-04-10T21:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator Script for merging fields with conditions.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663452#M51554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks on replies everyone..&lt;/P&gt;&lt;P&gt;I am novice to&amp;nbsp; any type of scripting so I don't get it what to type in field calculator..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need script which will populate new field, make&amp;nbsp;concatenation of three fields (GJ, Odeljenje, Odsek) with couple conditions in field Odeljenje (test length of the content) and in field Odsek (test is the content number and length of it and if it is not change the case of text),&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;basically translate excel formula&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CONCATENATE(A2,IF(LEN(B2)=1,CONCATENATE("00",B2),IF(LEN(B2)=2,CONCATENATE("0",B2),B2)),IF(ISNUMBER(C2+1),IF(LEN(C2)&amp;lt;2,CONCATENATE("0",C2),C2),LOWER(C2)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to script (either with python or vba).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2019 07:14:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663452#M51554</guid>
      <dc:creator>VukCeperkovic1</dc:creator>
      <dc:date>2019-04-11T07:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Field calculator Script for merging fields with conditions.</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663453#M51555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My guess, because I can't load the spreadsheet because of the embedded vba and just going by your screen grab of the perfect output. Here are 2 examples&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;
&lt;SPAN class="string token"&gt;"{:&amp;gt;04.0f}{:&amp;gt;03.0f}{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;11&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'z'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;lower&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;'0011002z'&lt;/SPAN&gt;

&lt;SPAN class="string token"&gt;"{:&amp;gt;04.0f}{:&amp;gt;03.0f}{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1009&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;17&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'A'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;lower&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;'1009017a'&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which would suggest that your field calculator expression using a python parser with fields named&lt;/P&gt;&lt;P&gt;!A!, !B!, !C! would be&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{:&amp;gt;04.0f}{:&amp;gt;03.0f}{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!A!&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !B!&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !C!&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;lower&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This translates to&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;{:&amp;gt;04.0f}&lt;/SPAN&gt;&amp;nbsp; means 4 character spaces with 0 padding, hence if the width of the number is 2, you&amp;nbsp; get 2 padded 0's&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;{:&amp;gt;03.0f}&lt;/SPAN&gt;&amp;nbsp; same as above, but a 3 character space with 0 padding.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;{}&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; means, just a string representation&lt;/P&gt;&lt;P&gt;The ! marks are thrown around the field name if using a python parser&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the 2nd example block is the field calculator expression when you replace A, B, C with the actual field names, and you are calculating into a new text field&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:02:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-script-for-merging-fields-with/m-p/663453#M51555</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T04:02:58Z</dc:date>
    </item>
  </channel>
</rss>

