<?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: If...then...elseif...else...endif in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266264#M398857</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try to do you if tests with the account_code directly as you have already prepared it in your first load. You might have a hard to detect problem with trailing spaces in your gl_code. If you have trailing space or spaces in this field your logic will not work. The spaces are of course invisible to the human eye depending on where they appear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So write this instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF account_code = 20400 THEN&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;ELSEIF account_code = 20300 THEN&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a shorter code anyway and according to your screenshot the account codes when being separated out in the first LOAD it will convert them into numbers and will remove automatically the trailing spaces.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 25 Feb 2017 12:08:30 GMT</pubDate>
    <dc:creator>petter</dc:creator>
    <dc:date>2017-02-25T12:08:30Z</dc:date>
    <item>
      <title>If...then...elseif...else...endif</title>
      <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266263#M398856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi community.&lt;/P&gt;&lt;P&gt;Could someone please tell me why this script doesn't work properly. &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;it runs but seems to ignore the IF statement and just runs the code after "ELSE". &lt;/SPAN&gt;Think something is wrong with my if "condition'' as everything fall through to the "else" bucket. (even if it does meet the condition criteria). I'm thinking it could be a syntax issue? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="154448" alt="Untitled2.png" class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/154448_Untitled2.png" style="height: 650px; width: 620px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Facts_Truck_Cost:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; MonthYear,&lt;/P&gt;&lt;P&gt;&amp;nbsp; gl_code,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Truck_ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Margin_Flag,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Allocation_Flag,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Truck_Cost,&lt;/P&gt;&lt;P&gt;&amp;nbsp; SubField(gl_code,'-',4) as account_code&lt;/P&gt;&lt;P&gt;FROM [..\Testing\Qlik MODEL QVD\Direct_Cost_Trucks_Table.qvd] (qvd);&lt;/P&gt;&lt;P&gt;\&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Allocation of each gl account with special portions and all gl accounts to truck legs&lt;/P&gt;&lt;P&gt;//////////////////// 20400 (Interislander Cost to SI routes only)&lt;/P&gt;&lt;P&gt;IF (SubField(gl_code,'-',4)) = '20400' THEN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Facts_Truck_Cost_Allocation:&lt;/P&gt;&lt;P&gt;&amp;nbsp; NoConcatenate&lt;/P&gt;&lt;P&gt;&amp;nbsp; Load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Distance','IntD',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Weight','IntW',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Activity','IntA',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Revenue','IntR',0))))&lt;/P&gt;&lt;P&gt;&amp;nbsp; as Truck_Cost_leg&lt;/P&gt;&lt;P&gt;&amp;nbsp; Resident Facts_Truck_Cost&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//////////////////// 20300 (Subcontractor Cost to Subbies and subby customers only)&lt;/P&gt;&lt;P&gt;ELSEIF(SubField (gl_code,'-',4)) = '20300' THEN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Facts_Truck_Cost_Allocation:&lt;/P&gt;&lt;P&gt;&amp;nbsp; NoConcatenate&lt;/P&gt;&lt;P&gt;&amp;nbsp; Load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Distance','SUBD',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Weight','SUBW',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Activity','SUBA',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Revenue','SUBR',0))))&lt;/P&gt;&lt;P&gt;&amp;nbsp; as Truck_Cost_leg&lt;/P&gt;&lt;P&gt;&amp;nbsp; Resident Facts_Truck_Cost&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//////////////////// ALL OTHER (NON SPECIAL) MTD PORTION TO ALL LEGS&lt;/P&gt;&lt;P&gt;ELSE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Facts_Truck_Cost_Allocation:&lt;/P&gt;&lt;P&gt;&amp;nbsp; NoConcatenate&lt;/P&gt;&lt;P&gt;&amp;nbsp; Load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Distance','OtherD',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Weight','OtherW',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Activity','OtherA',&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Allocation_Flag = 'Revenue','OtherR',0))))&lt;/P&gt;&lt;P&gt;&amp;nbsp; as Truck_Cost_leg&lt;/P&gt;&lt;P&gt;&amp;nbsp; Resident Facts_Truck_Cost&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;ENDIF&lt;/P&gt;&lt;P&gt;Drop table Facts_Truck_Cost;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="154417" alt="Untitled.png" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/154417_Untitled.png" style="height: 392px; width: 620px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: Result image added&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Feb 2017 10:01:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266263#M398856</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-02-25T10:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: If...then...elseif...else...endif</title>
      <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266264#M398857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try to do you if tests with the account_code directly as you have already prepared it in your first load. You might have a hard to detect problem with trailing spaces in your gl_code. If you have trailing space or spaces in this field your logic will not work. The spaces are of course invisible to the human eye depending on where they appear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So write this instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF account_code = 20400 THEN&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;ELSEIF account_code = 20300 THEN&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a shorter code anyway and according to your screenshot the account codes when being separated out in the first LOAD it will convert them into numbers and will remove automatically the trailing spaces.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Feb 2017 12:08:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266264#M398857</guid>
      <dc:creator>petter</dc:creator>
      <dc:date>2017-02-25T12:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: If...then...elseif...else...endif</title>
      <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266265#M398858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Chantelle,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Trust that you are doing well!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Considering your logic, SubField Function will not work as expected. Please use below given sample script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14880250673779432 jive_text_macro" jivemacro_uid="_14880250673779432"&gt;
&lt;P&gt;Facts_Truck_Cost:&lt;/P&gt;
&lt;P&gt;LOAD MonthYear,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gl_code,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Truck_ID,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin_Flag,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Allocation_Flag,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Truck_Cost,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(SubField(gl_code,'-',4) = '20400', 'Int', If(SubField(gl_code,'-',4) = '20300', 'SUB', 'Other'))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; If(Allocation_Flag = 'Distance','D',&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(Allocation_Flag = 'Weight','W',&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(Allocation_Flag = 'Activity','A',&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(Allocation_Flag = 'Revenue','R',0)))) AS Truck_Cost_leg&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(SubField(gl_code,'-',4) = '20400', 'Int', If(SubField(gl_code,'-',4) = '20300', 'SUB', 'Other'))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; Left(Allocation_Flag, 1) AS Truck_Cost_leg&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;
&lt;P&gt;FROM&lt;/P&gt;
&lt;P&gt;Direct_Cost_Trucks_Table.xlsx&lt;/P&gt;
&lt;P&gt;(ooxml, embedded labels, table is Facts_Truck_Cost);&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this will be helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;Rahul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Feb 2017 12:23:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266265#M398858</guid>
      <dc:creator>rahulpawarb</dc:creator>
      <dc:date>2017-02-25T12:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: If...then...elseif...else...endif</title>
      <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266266#M398859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;request you to send me a sample data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Feb 2017 12:32:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266266#M398859</guid>
      <dc:creator>shivkumar300</dc:creator>
      <dc:date>2017-02-25T12:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: If...then...elseif...else...endif</title>
      <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266267#M398860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With all due respects Sir -&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt; the SubField()-function can be used BOTH inside a LOAD and outside of a LOAD&lt;/STRONG&gt;&lt;/SPAN&gt; in a load-script. There is no doubt about it - if you don't believe me do a real test yourself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a load statement it is either an aggregation function - if it has two parameters, or a regular string extraction function if it has three parameters. Outside a load-statement it is just a string extraction function that need three parameters - just as it would be in the UI expressions in a running application.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Feb 2017 12:40:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266267#M398860</guid>
      <dc:creator>petter</dc:creator>
      <dc:date>2017-02-25T12:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: If...then...elseif...else...endif</title>
      <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266268#M398861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Petter,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sincere apologies for not being clear in prior response &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/sad.png" /&gt;. I 100% agree with you; I mean to say &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;SubField &lt;/SPAN&gt;function will not work as expected considering logic written by &lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;Chantelle&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once again extremely sorry for putting ambiguous response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;Rahul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Feb 2017 14:24:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266268#M398861</guid>
      <dc:creator>rahulpawarb</dc:creator>
      <dc:date>2017-02-25T14:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: If...then...elseif...else...endif</title>
      <link>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266269#M398862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your response Petter. I tried your suggestion but unfortunately it still behaves the same. So I must have something else wrong also.&amp;nbsp; I have however managed to get the desired result with nested if functions. It looks a bit clunky but works &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 25 Feb 2017 22:38:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/If-then-elseif-else-endif/m-p/1266269#M398862</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-02-25T22:38:41Z</dc:date>
    </item>
  </channel>
</rss>

