<?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: Broken Expression in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134106#M92169</link>
    <description>&lt;P&gt;The most simple way to validate respectively trouble-shoot a complex expression is to separate each single part as an own expression and then combining them again - against all relevant selection states. No other approach could ensure that really everything works like expected and is returning the wanted results.&lt;/P&gt;
&lt;P&gt;Of course this could become quite time consuming and is a rather ugly job. Much better would be to avoid such complex approaches and using more simple expressions - ideally avoiding all if-loops and aggr() constructs by transferring the essential logic into the data-model, for example by creating relevant flag-fields.&lt;/P&gt;
&lt;P&gt;Beside this it's not very likely that the expression itself is broken between View and Sense else the underlying data and/or the data-model isn't the same anymore. The slightest change in the load-processing until this application and/or within the settings may impact the results. Therefore I suggest to check the data first. Useful would be to put all relevant fields in a table-box and then applying the relevant selection states to see if there any data available and does they have the needed associations.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Nov 2023 13:21:56 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2023-11-02T13:21:56Z</dc:date>
    <item>
      <title>Broken Expression</title>
      <link>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134069#M92165</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I have an expression in QlikSense that keeps returning zero value. For context we recently migrated from QlikView and same expression works fine. I'm also new to QlikSense so I don't really know where the problem could be.&lt;/P&gt;
&lt;P&gt;This is the expression:&lt;/P&gt;
&lt;DIV&gt;=num(&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; SUM({$}&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if(PART.PRODUCT_CODE='GTM'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ORKORDER_BASE_ID)),0,AGGR(SUM(OPERATION.DEVIATED_QTY),OPERATION.WORKORDER_BASE_ID))+(OPERATION.DEVIATED_QTY))&amp;gt;=WORK_ORDER.RECEIVED_QTY,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; OPERATION.COMPLETED_QTY-WORK_ORDER.RECEIVED_QTY&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; -if(IsNull(AGGR(SUM(OPERATION.DEVIATED_QTY),OPERATION.WORKORDER_BASE_ID)),0,AGGR(SUM(OPERATION.DEVIATED_QTY),OPERATION.WORKORDER_BASE_ID))&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; +(OPERATION.DEVIATED_QTY),0&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; )*if(IsNull(PART_SITE.UNIT_PRICE)=0,PART_SITE.UNIT_PRICE,PART_SITE.UNIT_MATERIAL_COST) &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; ),'£#,##0')&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;I suspect it might have to do with the aggregation. I'll appreciate any insight on how to tackle this.&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 02 Nov 2023 11:24:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134069#M92165</guid>
      <dc:creator>ba11</dc:creator>
      <dc:date>2023-11-02T11:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Broken Expression</title>
      <link>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134106#M92169</link>
      <description>&lt;P&gt;The most simple way to validate respectively trouble-shoot a complex expression is to separate each single part as an own expression and then combining them again - against all relevant selection states. No other approach could ensure that really everything works like expected and is returning the wanted results.&lt;/P&gt;
&lt;P&gt;Of course this could become quite time consuming and is a rather ugly job. Much better would be to avoid such complex approaches and using more simple expressions - ideally avoiding all if-loops and aggr() constructs by transferring the essential logic into the data-model, for example by creating relevant flag-fields.&lt;/P&gt;
&lt;P&gt;Beside this it's not very likely that the expression itself is broken between View and Sense else the underlying data and/or the data-model isn't the same anymore. The slightest change in the load-processing until this application and/or within the settings may impact the results. Therefore I suggest to check the data first. Useful would be to put all relevant fields in a table-box and then applying the relevant selection states to see if there any data available and does they have the needed associations.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 13:21:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134106#M92169</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2023-11-02T13:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Broken Expression</title>
      <link>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134191#M92179</link>
      <description>&lt;P&gt;Tricky to check without knowing the correct answer and not having the data model in front of me.&lt;/P&gt;
&lt;P&gt;But like Marcus said, check your data model first. If this works in QlikView, it should work in Qlik Sense, ASSUMING the model hasn't changed.&lt;/P&gt;
&lt;P&gt;Anyway, I took some help from a "friend" (ChatGPT) and refactorized the expression a bit by removing nested if statements and putting what's possible in set analysis. After doing this, I couldn't understand why the Aggr() is there.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;=Num(
    Sum(
        {$&amp;lt;
            PART.PRODUCT_CODE = {'GTM', 'VTM', 'SC'}
        ,   WORK_ORDER.STATUS = {'R'}
        ,   WORK_ORDER.SUB_ID = {0}
        ,   OPERATION.COMPLETED_QTY -= {0}
        &amp;gt;} 
        If(
            OPERATION.SEQUENCE_NO = 
                // This Aggr should probably be inside something like min/max, other wise, why not just do min without the aggr?
                Aggr(
                    Min(
                        {$&amp;lt;
                            WORK_ORDER.STATUS = {'R'}
                        ,   WORK_ORDER.SUB_ID = {0}
                        ,   OPERATION.COMPLETED_QTY -= {0}
                        &amp;gt;}
                        OPERATION.SEQUENCE_NO
                    )
                ,   OPERATION.WORKORDER_BASE_ID
                )
            And WORK_ORDER.RECEIVED_QTY &amp;lt;=
                    (
                        OPERATION.COMPLETED_QTY
                        -
                        Alt(
                            // This Aggr should probably be inside something like min/max, other wise, why not just do sum without the aggr?
                            Aggr(
                                Sum(OPERATION.DEVIATED_QTY)
                            ,   OPERATION.WORKORDER_BASE_ID
                            )
                        ,   0
                        )
                        +
                        OPERATION.DEVIATED_QTY
                    )
        ,   OPERATION.COMPLETED_QTY
            -
            WORK_ORDER.RECEIVED_QTY
            -
            Alt(
                // This Aggr should probably be inside something like min/max, other wise, why not just do sum without the aggr?
                Aggr(
                    Sum(OPERATION.DEVIATED_QTY)
                ,   OPERATION.WORKORDER_BASE_ID
                )
            ,   0
            )
            +
            OPERATION.DEVIATED_QTY
        ,   0
        )
        *
        Alt(PART_SITE.UNIT_PRICE, PART_SITE.UNIT_MATERIAL_COST)
    )
,   '£#,##0'
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:20:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134191#M92179</guid>
      <dc:creator>MattiasThalén</dc:creator>
      <dc:date>2023-11-02T15:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Broken Expression</title>
      <link>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134441#M92188</link>
      <description>&lt;P&gt;Thank you, will have another crack at it and see what happens. Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 10:43:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Broken-Expression/m-p/2134441#M92188</guid>
      <dc:creator>ba11</dc:creator>
      <dc:date>2023-11-03T10:43:29Z</dc:date>
    </item>
  </channel>
</rss>

