<?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: Formulae not working in IF statement in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507250#M1226432</link>
    <description>&lt;P&gt;Thank you everyone for the suggestions. I have tried the coalesce option, but still do not get the correct answer. I will raise it as a bug with Qlik via our VAR.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2025 17:33:02 GMT</pubDate>
    <dc:creator>braham</dc:creator>
    <dc:date>2025-02-25T17:33:02Z</dc:date>
    <item>
      <title>Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506110#M1226400</link>
      <description>&lt;P&gt;Morning&lt;/P&gt;
&lt;P&gt;I hope that I will be able to get some insight into my issue with the assistance of those more knowledgeable than me. I am running QlikView May 2023.&lt;/P&gt;
&lt;P&gt;I have a scenario where I need to test to see if a value of a name field exits in table A and if not use the value in table B for a dimension. If it exits in table A I will use it. To do this I use the IF statement combined with the IFNull to test if field A exists. Here is the code:&lt;/P&gt;
&lt;P&gt;=If(IsNull(Aggr(FirstSortedValue({$&amp;lt;BGDRELATION = {'M'}&amp;gt;} Distinct SchemeName_MA, -BGDDATE), BGDMEMBERNO)), &lt;BR /&gt;&amp;nbsp;Aggr(FirstSortedValue({$&amp;lt;MMD_ActiveMemberRaised = {'1'}, MMD_Relationship = {'M'}&amp;gt;} Distinct SchemeName, -LNK_CCYYMM), LNK_Member),&lt;BR /&gt;Aggr(FirstSortedValue({$&amp;lt;BGDRELATION = {'M'}&amp;gt;} Distinct SchemeName_MA, -BGDDATE), BGDMEMBERNO))&lt;/P&gt;
&lt;P&gt;An added complication is that the Field A is stored by month and can therefore change over time. When reporting over more than 1 month I want to pick up the last value (hence the FirstSortedValue).&lt;/P&gt;
&lt;P&gt;My frustration with this statement is that for a very small percentage of the records I get a Null value being reported. When identifying one record that returns a null, I look at the values of the name field in both records and there are valid values. When I only run the code to extract from a file&amp;nbsp;A I get the correct answer and when I only run the code to only extract from file B I also get the correct answer. Each of the statements works when not part of the IF statement, but when put in the IF statement it returns a Null instead of the correct value.&lt;/P&gt;
&lt;P&gt;I changed the If statement to return a string 'Is Null' or 'Is not Null' and when the value is there (in my selected example) I get 'Is not null', which is what I expect, so the If test seems to be applied.&lt;/P&gt;
&lt;P&gt;Has anyone got some insight into what is happening when QlikView processes an if statement that may provide some insight as to why I am not getting the correct answer?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for your assistance.&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Braham Edwards&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 08:53:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506110#M1226400</guid>
      <dc:creator>braham</dc:creator>
      <dc:date>2025-02-17T08:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506124#M1226401</link>
      <description>&lt;P&gt;Hi! &lt;BR /&gt;reason is still unknown to me, but I think it is a common issue in QlikView where Aggr() and FirstSortedValue() behave differently within an If() statement compared to when they are used individually.&lt;/P&gt;
&lt;P&gt;An idea is if FirstSortedValue() is returning null due to duplicate values, to use Only() inside Aggr():&lt;BR /&gt;Aggr(Only({$&amp;lt;BGDRELATION = {'M'}&amp;gt;} SchemeName_MA), BGDMEMBERNO)&lt;/P&gt;
&lt;P&gt;or use len() instead of IsNull():&lt;BR /&gt;If(Len(Aggr(FirstSortedValue({$&amp;lt;BGDRELATION = {'M'}&amp;gt;} Distinct SchemeName_MA, -BGDDATE), BGDMEMBERNO)))=0,&lt;/P&gt;
&lt;P&gt;This often works better inside If() than IsNull()&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 09:34:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506124#M1226401</guid>
      <dc:creator>diegozecchini</dc:creator>
      <dc:date>2025-02-17T09:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506153#M1226402</link>
      <description>&lt;P&gt;Thanks, let me try that and I will revert.&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 11:14:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506153#M1226402</guid>
      <dc:creator>braham</dc:creator>
      <dc:date>2025-02-17T11:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506460#M1226414</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Had an opportunity to test these 2 solutions. Unfortunately, neither returned the desired results. Both returned the correct answers when executed outside the If statement.&lt;/P&gt;
&lt;P&gt;Thanks for the suggestion.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 19:32:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506460#M1226414</guid>
      <dc:creator>braham</dc:creator>
      <dc:date>2025-02-18T19:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506575#M1226417</link>
      <description>&lt;P&gt;Hi! &lt;BR /&gt;If available, Coalesce() can be more efficient than If() for handling nulls.&lt;/P&gt;
&lt;P&gt;Coalesce(vSchemeNameA, vSchemeNameB)&lt;/P&gt;
&lt;P&gt;Other idea could be to define each part separately in variables and use them in the If() statement to debug what is returning null.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 10:53:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506575#M1226417</guid>
      <dc:creator>diegozecchini</dc:creator>
      <dc:date>2025-02-19T10:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506588#M1226418</link>
      <description>&lt;P&gt;What happens with the following (simplified) approach as calculated dimension:&lt;/P&gt;
&lt;P&gt;aggr(coalesce(&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Firstsortedvalue(...), Firstsortedvalue(...), concat(...), concat(...), '#NV'),&lt;BR /&gt;Dim)&lt;/P&gt;
&lt;P&gt;It will return the first not NULL result whereby the concat() is aimed to display the n possible values which leads to a NULL result by a firstsortedvalue() and the last is a general default. You may also add an extra order-information to the output, like:&lt;/P&gt;
&lt;P&gt;... '1. ' &amp;amp; firstsortedvalue(),&amp;nbsp;'2. ' &amp;amp; firstsortedvalue(), ...&lt;/P&gt;
&lt;P&gt;to identify exactly from where which result is coming. And the next step might be to add n further dimensions to the table to see more details.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 11:42:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2506588#M1226418</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2025-02-19T11:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507250#M1226432</link>
      <description>&lt;P&gt;Thank you everyone for the suggestions. I have tried the coalesce option, but still do not get the correct answer. I will raise it as a bug with Qlik via our VAR.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 17:33:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507250#M1226432</guid>
      <dc:creator>braham</dc:creator>
      <dc:date>2025-02-25T17:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507251#M1226433</link>
      <description>&lt;P&gt;Ditto, for me most of the times Len function gave me accurate results than IS NULL in calculations.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 18:16:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507251#M1226433</guid>
      <dc:creator>gq</dc:creator>
      <dc:date>2025-02-25T18:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507320#M1226437</link>
      <description>&lt;P&gt;Why should there be a bug? Just because there are some results NULL? If there is any NULL it means that the table-associations respectively the data-model isn't suitable and/or the data-set hasn't the data like expected.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 06:18:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507320#M1226437</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2025-02-26T06:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507785#M1226444</link>
      <description>&lt;P&gt;Hi Marcus, Thanks for the response. The data is as expected, that is why I need to check for null values. I am trying to understand why the statements deliver the correct results when executed outside the if statement but fail when executed in the if statement. Perhaps I am not understanding how QlikView evaluates an if statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 10:20:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507785#M1226444</guid>
      <dc:creator>braham</dc:creator>
      <dc:date>2025-02-28T10:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Formulae not working in IF statement</title>
      <link>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507803#M1226445</link>
      <description>&lt;P&gt;IMO it's not related to the if() else to the fact that now not n separate views are there else they will be combined. This means these views needs to have a valid association to each other - and quite probably that's not the case in your scenario.&lt;/P&gt;
&lt;P&gt;A quite common example for such challenges are views of sales against budgets. The operative data-sources are usually a fact-table for each one - and in nearly each case they couldn't be directly linked because not each sales were planned and reverse the same that not each budget has appropriate sales.&lt;/P&gt;
&lt;P&gt;This means there are missing key-values on both sides which are not solvable - no way, never - at least not directly. The reason is that there is no association respectively the association is NULL. But this couldn't be queried and therefore fetched - only cells could be queried if they have a value or are NULL or EMPTY.&lt;/P&gt;
&lt;P&gt;I assume that your issue has similar reasons. If so you will need to adjust the data-model - which is often not difficult. Regarding to the sales/budget example above it could be quickly solved by concatenating the sales and budget facts into a single fact-table by harmonizing the field-names and data-structures as much as possible and adding the source-information within an extra field.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 12:02:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Formulae-not-working-in-IF-statement/m-p/2507803#M1226445</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2025-02-28T12:02:14Z</dc:date>
    </item>
  </channel>
</rss>

