<?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() in dimension returns false despite true condition — works fine in measure in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2517916#M105997</link>
    <description>&lt;P&gt;1) Qlik always evaluates both the True and False condition if both are provided.&lt;/P&gt;&lt;P&gt;2) When used in a measure, your expression implicitly becomes:&lt;/P&gt;&lt;P&gt;=Only(if($(vVariable1)=1, 1, if(len(Field_X)=0, NULL(), 1)))&lt;/P&gt;&lt;P&gt;So that's what you want to be testing if you are cross-checking dimensions and measures.&lt;/P&gt;&lt;P&gt;I haven't had a chance to actually run the same scenario, so just general stuff here.&lt;/P&gt;</description>
    <pubDate>Thu, 15 May 2025 10:20:21 GMT</pubDate>
    <dc:creator>Or</dc:creator>
    <dc:date>2025-05-15T10:20:21Z</dc:date>
    <item>
      <title>if() in dimension returns false despite true condition — works fine in measure</title>
      <link>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2517909#M105996</link>
      <description>&lt;P class=""&gt;Hi everyone,&lt;/P&gt;&lt;P class=""&gt;I’m facing unexpected behavior with an if() statement in Qlik Sense &lt;STRONG&gt;when used in a dimension&lt;/STRONG&gt;, and I’d really appreciate your help understanding it.&lt;/P&gt;&lt;P class=""&gt;I have a variable vVariable1 that currently holds the value 1.&lt;/P&gt;&lt;P class=""&gt;Here are two expressions I’m testing:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;1.&amp;nbsp;=if($(vVariable1)=1, 1, 0)&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;→ Returns 1, as expected.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;2.&amp;nbsp;&lt;SPAN&gt;=if($(vVariable1)=1, 1, if(len(Field_X)=0, NULL(), 1))&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;→ Returns NULL(), even though $(vVariable1)=1 should cause the expression to return 1 immediately.&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;Important detail:&lt;/STRONG&gt;&lt;BR /&gt;This only happens when I use the expression in a &lt;STRONG&gt;dimension&lt;/STRONG&gt;.&lt;BR /&gt;If I use the exact same logic in a &lt;STRONG&gt;measure&lt;/STRONG&gt;, it works as expected — it returns 1 and does not evaluate the nested condition.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mira_io_0-1747301781359.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/180509iFEF6E0D9A00B4169/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mira_io_0-1747301781359.png" alt="Mira_io_0-1747301781359.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P class=""&gt;In the expression editor, Qlik correctly interprets this as:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mira_io_2-1747301870408.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/180511i33802FB6F5C04C29/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mira_io_2-1747301870408.png" alt="Mira_io_2-1747301870408.png" /&gt;&lt;/span&gt;&lt;P&gt;&lt;SPAN&gt;So I would expect it to just return &lt;/SPAN&gt;1&lt;SPAN&gt;, regardless of what comes next.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P class=""&gt;&lt;STRONG&gt;My question:&lt;/STRONG&gt;&lt;BR /&gt;Is this expected behavior in dimensions?&lt;BR /&gt;Does Qlik always evaluate both branches of an if() when used in dimensions — even if the condition is already satisfied?&lt;/P&gt;&lt;P class=""&gt;And what would be the best way to structure such logic in a dimension to avoid this issue?&lt;/P&gt;&lt;P class=""&gt;Thanks in advance for any insights!&lt;/P&gt;&lt;P class=""&gt;Best regards,&lt;BR /&gt;Mira&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 09:39:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2517909#M105996</guid>
      <dc:creator>Mira_io</dc:creator>
      <dc:date>2025-05-15T09:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: if() in dimension returns false despite true condition — works fine in measure</title>
      <link>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2517916#M105997</link>
      <description>&lt;P&gt;1) Qlik always evaluates both the True and False condition if both are provided.&lt;/P&gt;&lt;P&gt;2) When used in a measure, your expression implicitly becomes:&lt;/P&gt;&lt;P&gt;=Only(if($(vVariable1)=1, 1, if(len(Field_X)=0, NULL(), 1)))&lt;/P&gt;&lt;P&gt;So that's what you want to be testing if you are cross-checking dimensions and measures.&lt;/P&gt;&lt;P&gt;I haven't had a chance to actually run the same scenario, so just general stuff here.&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 10:20:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2517916#M105997</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2025-05-15T10:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: if() in dimension returns false despite true condition — works fine in measure</title>
      <link>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2517927#M105998</link>
      <description>&lt;P class=""&gt;Thanks a lot for the explanation — that really helps clarify things!&lt;/P&gt;&lt;P class=""&gt;Just to double-check my understanding: you're saying that in a measure like&lt;BR /&gt;=Only(if($(vVariable1)=1, 1, if(len(Field_X)=0, NULL(), 1)))&lt;BR /&gt;the inner if is still evaluated fully (true and false parts), but because it's wrapped in Only(), I might not see any issues unless multiple results or NULLs are involved — is that correct?&lt;/P&gt;&lt;P class=""&gt;In contrast, in a dimension, even if $(vVariable1)=1 is true, the second part still gets evaluated, and if Field_X is NULL or causes an error, it breaks the row, which is why I see unexpected NULLs even though the first condition should apply?&lt;/P&gt;&lt;P class=""&gt;That would explain why it works fine as a measure but not as a dimension in my case. Let me know if I'm getting that right!&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 11:24:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2517927#M105998</guid>
      <dc:creator>Mira_io</dc:creator>
      <dc:date>2025-05-15T11:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: if() in dimension returns false despite true condition — works fine in measure</title>
      <link>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2518012#M106014</link>
      <description>&lt;P&gt;the calculated dimension always needs to have an aggregation&lt;BR /&gt;so your calculated dimension's expression would look like this:&lt;BR /&gt;aggr(only(&lt;SPAN&gt;if($(vVariable1)=1, 1, if(len(Field_X)=0, NULL(), 1)),Filed_X)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 May 2025 06:45:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2518012#M106014</guid>
      <dc:creator>ali_hijazi</dc:creator>
      <dc:date>2025-05-16T06:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: if() in dimension returns false despite true condition — works fine in measure</title>
      <link>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2518122#M106047</link>
      <description>&lt;P&gt;Both sides get evaluated regardless, but that shouldn't impact which branch is actually picked. That said, evaluation errors can presumably break the formula, yes.&lt;/P&gt;&lt;P&gt;As mentioned by Ali, you will likely want to use some form of aggr() if you're using something like this in a calculated dimension.&lt;/P&gt;&lt;P&gt;Recommended reading:&lt;/P&gt;&lt;P&gt;For aggr():&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/t5/Design/The-Aggregation-Scope/ba-p/1467321" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Design/The-Aggregation-Scope/ba-p/1467321&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For If():&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/t5/Official-Support-Articles/Why-Is-It-Not-A-Good-Idea-To-Use-Nested-If-Statements/ta-p/1713042" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Official-Support-Articles/Why-Is-It-Not-A-Good-Idea-To-Use-Nested-If-Statements/ta-p/1713042&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://qlikviewcookbook.com/2021/08/if-tips/" target="_blank" rel="noopener"&gt;https://qlikviewcookbook.com/2021/08/if-tips/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://qlikviewcookbook.com/2014/12/how-to-choose-an-expression/" target="_blank" rel="noopener"&gt;https://qlikviewcookbook.com/2014/12/how-to-choose-an-expression/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 May 2025 07:58:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/if-in-dimension-returns-false-despite-true-condition-works-fine/m-p/2518122#M106047</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2025-05-18T07:58:42Z</dc:date>
    </item>
  </channel>
</rss>

