<?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 SQL If Statement in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/SQL-If-Statement/m-p/432022#M486370</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to recreate the following SQL if statement in Qlikview:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if {F0902.GBLT} = "AA"&lt;/P&gt;&lt;P&gt;and ({F0902.GBFY}) = ({?Year}) &lt;/P&gt;&lt;P&gt;and (({F0902.GBOBJ} in '27000' to '27999')&lt;/P&gt;&lt;P&gt;or ({F0902.GBOBJ} in '31000' to '31999')&lt;/P&gt;&lt;P&gt;or ({F0902.GBOBJ} in '42000' to '42399'))&lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;{F0902.GBAPYC}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the set Analysis correct however I am having trouble wording the Qlikview if statement so that it Sums GBAPYC if 27000 object range has a value or sums the 27000 + 31000 range if the 31000 has a value and ignores 42000 range or it sums 27000 + 42000 if the 42000 has a value and ignores the 31000 range.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I have so far is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;({&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;PeriodwithAPYC&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections(PeriodwithAPYC))', 'BegBal'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Ledger Type]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'AA'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Fiscal Year]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections([Fiscal Year])-1)'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Object Account]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'&amp;gt;=31000 &amp;lt;=31999'}&amp;gt;}&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Amount&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)&amp;lt;&amp;gt;0, &lt;BR /&gt;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(vActualYTDLY31000)&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;({&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;PeriodwithAPYC&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections(PeriodwithAPYC))', 'BegBal'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Ledger Type]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'AA'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Fiscal Year]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections([Fiscal Year])-1)'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Object Account]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'&amp;gt;=42000 &amp;lt;=43299'}&amp;gt;}&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Amount&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)&amp;lt;&amp;gt;0,&lt;BR /&gt;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(=vActualYTDLY42000)&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;, 0&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;The variables do the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(vActualYTDLY31000) = Sums 27000 range and the 31000 range&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(=vActualYTDLY42000) - Sums 27000 raneg and the 42000 range&lt;/EM&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;So my if statment is saying if the 31000 range is not equal to 0 (as it contains negative &amp;amp; positive amounts) then Sum 27000 range + 31000 Range or if the 42000 range is not equal to 0 sum 27000 range + 42000 range.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please advise if you can help me with this one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nikki Fairgrieve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Mar 2013 09:46:27 GMT</pubDate>
    <dc:creator />
    <dc:date>2013-03-12T09:46:27Z</dc:date>
    <item>
      <title>SQL If Statement</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-If-Statement/m-p/432022#M486370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to recreate the following SQL if statement in Qlikview:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if {F0902.GBLT} = "AA"&lt;/P&gt;&lt;P&gt;and ({F0902.GBFY}) = ({?Year}) &lt;/P&gt;&lt;P&gt;and (({F0902.GBOBJ} in '27000' to '27999')&lt;/P&gt;&lt;P&gt;or ({F0902.GBOBJ} in '31000' to '31999')&lt;/P&gt;&lt;P&gt;or ({F0902.GBOBJ} in '42000' to '42399'))&lt;/P&gt;&lt;P&gt;then &lt;/P&gt;&lt;P&gt;{F0902.GBAPYC}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the set Analysis correct however I am having trouble wording the Qlikview if statement so that it Sums GBAPYC if 27000 object range has a value or sums the 27000 + 31000 range if the 31000 has a value and ignores 42000 range or it sums 27000 + 42000 if the 42000 has a value and ignores the 31000 range.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I have so far is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;({&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;PeriodwithAPYC&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections(PeriodwithAPYC))', 'BegBal'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Ledger Type]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'AA'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Fiscal Year]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections([Fiscal Year])-1)'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Object Account]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'&amp;gt;=31000 &amp;lt;=31999'}&amp;gt;}&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Amount&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)&amp;lt;&amp;gt;0, &lt;BR /&gt;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(vActualYTDLY31000)&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;,&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;sum&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;({&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;PeriodwithAPYC&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections(PeriodwithAPYC))', 'BegBal'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Ledger Type]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'AA'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Fiscal Year]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'$(=getfieldselections([Fiscal Year])-1)'}, &lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;[Object Account]&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;={'&amp;gt;=42000 &amp;lt;=43299'}&amp;gt;}&lt;/SPAN&gt;&lt;SPAN style="color: #800000; font-size: 8pt;"&gt;Amount&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)&amp;lt;&amp;gt;0,&lt;BR /&gt;&lt;BR /&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(=vActualYTDLY42000)&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt;, 0&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;)) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;The variables do the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(vActualYTDLY31000) = Sums 27000 range and the 31000 range&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;$(=vActualYTDLY42000) - Sums 27000 raneg and the 42000 range&lt;/EM&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;So my if statment is saying if the 31000 range is not equal to 0 (as it contains negative &amp;amp; positive amounts) then Sum 27000 range + 31000 Range or if the 42000 range is not equal to 0 sum 27000 range + 42000 range.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please advise if you can help me with this one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nikki Fairgrieve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 09:46:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-If-Statement/m-p/432022#M486370</guid>
      <dc:creator />
      <dc:date>2013-03-12T09:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: SQL If Statement</title>
      <link>https://community.qlik.com/t5/QlikView/SQL-If-Statement/m-p/432023#M486371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Usually if statements in expressions take the format sum(if(.... instead of if(sum(...&lt;/P&gt;&lt;P&gt;This is because you normally want to test the value at the field level, instead of aggregating a field before then testing.&lt;/P&gt;&lt;P&gt;If you are trying to replicate an SQL statement it too may need to be done at the field level instead of at an aggregated level.&lt;/P&gt;&lt;P&gt;Jonathan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 10:02:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SQL-If-Statement/m-p/432023#M486371</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-03-12T10:02:06Z</dc:date>
    </item>
  </channel>
</rss>

