<?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: Subtraction in Script part in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Subtraction-in-Script-part/m-p/2516078#M105746</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/242264"&gt;@MMK&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This might be a bit of a long way around, but it works. I also added more groups as this might not always be only 1 group in the data... I wasn't sure.&lt;/P&gt;&lt;P&gt;Here is the resulting Table&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JandreKillianRIC_0-1745911760783.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/180008i30AAF0804BF95421/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JandreKillianRIC_0-1745911760783.png" alt="JandreKillianRIC_0-1745911760783.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the script&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;////////////////////////////////////////////////////////////////////////////////
// Load inline with more than one group as this might be what is in the data and not
// just in the sample provided 
////////////////////////////////////////////////////////////////////////////////


TmpSales:
Load 
	*, 
    RecNo() as SortingTmp; // Adding this for the sorting in the front end
Load * Inline [
EMP,Sales
Group1,1000
E1,150
E2,200
E3,100
E4,250
E5,
E6,
E7,
Group2,1420
E1,150
E2,200
E3,100
E4,250
E5,
Group3,1970
E1,150
E2,200
E3,100
E4,250
E5,500
E6,600
E7,
E8,
E9,
];

////////////////////////////////////////////////////////////////////////////////
// Define group level per individual line item
////////////////////////////////////////////////////////////////////////////////

TmpSales2:
Load 
	SortingTmp,
	EMP, 
    IF(Sales = 0 or Len(Trim(Sales)) = 0, 0, Sales) as Sales, // Cleaning up the Sales for later
    IF(WildMatch(EMP, 'Group*'), 
    	EMP, Peek('GroupName')) as GroupName, // Getting the Group that the Sales belong to
    IF(WildMatch(EMP, 'Group*'), 
    	Sales, Peek('GroupSales')) as GroupSales // Adding the Group Totals as this is to be used later
Resident TmpSales; 

Drop Table TmpSales; 

////////////////////////////////////////////////////////////////////////////////
// Get totals per group (Excl the group values)
////////////////////////////////////////////////////////////////////////////////

GroupTotalsLineItems:
Left Join (TmpSales2)
Load 
	GroupName,  
    Sum(Sales) as TotalSales
Resident TmpSales2
Where Not WildMatch(EMP, 'Group*') // Excl the Group Value
Group By GroupName; 


////////////////////////////////////////////////////////////////////////////////
// Calculate the Others (Sales that are 0)
////////////////////////////////////////////////////////////////////////////////

TmpSales3:
Load 
    IF(Sales = 0, Peek('Sorting')+1, 
    	SortingTmp) as Sorting, // Fixing the sorting as we are grouping the Sales EMP where sales = 0
	EMP,
    IF(Sales = 0, 
    	'Others', 
        EMP) as ReportingEMP, 
    GroupName, 
    TotalSales, 
    GroupSales,
    Sales, 
    IF(Sales = 0 and Peek('ReportingEMP') &amp;lt;&amp;gt; 'Others', 
    	 GroupSales - TotalSales, 
        Sales) as ReportingSales
Resident TmpSales2
Order By SortingTmp;

Drop Table TmpSales2; 

////////////////////////////////////////////////////////////////////////////////
// Clean up table (Remove all 0's as this is catered for) 
////////////////////////////////////////////////////////////////////////////////

Sales:
NoConcatenate
Load 
	*
Resident TmpSales3
Where ReportingSales &amp;lt;&amp;gt; 0;

Drop Table TmpSales3; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards - Jandre&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;!--  
        Layout, Style or Voice Helpers
      --&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;!--  
        Compliance
      --&gt;&lt;DIV class=""&gt;&lt;!--   For autoSmartRem addNewWindowWarnings div is referenced in an aria-describedby   --&gt;&lt;DIV&gt;Opens in new window&lt;/DIV&gt;&lt;DIV&gt;PDF Download&lt;/DIV&gt;&lt;DIV&gt;Word Download&lt;/DIV&gt;&lt;DIV&gt;Excel Download&lt;/DIV&gt;&lt;DIV&gt;PowerPoint Download&lt;/DIV&gt;&lt;DIV&gt;Document Download&lt;/DIV&gt;&lt;/DIV&gt;&lt;!--  
        Versioning Control Panel if versioning = true !
      --&gt;&lt;!--  
        Launcher
      --&gt;&lt;!--   Toolbar   --&gt;&lt;!--  
        Site Menu
      --&gt;&lt;!--  
        Generic Aria Live message container
      --&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;!--   Symbol definitions   --&gt;&lt;/DIV&gt;&lt;!--   end #ae_app   --&gt;</description>
    <pubDate>Tue, 29 Apr 2025 07:30:59 GMT</pubDate>
    <dc:creator>JandreKillianRIC</dc:creator>
    <dc:date>2025-04-29T07:30:59Z</dc:date>
    <item>
      <title>Subtraction in Script part</title>
      <link>https://community.qlik.com/t5/App-Development/Subtraction-in-Script-part/m-p/2516009#M105738</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Thanks in advance for your support.&lt;/P&gt;&lt;P&gt;I am having a table with EMP and their sales. Under employee the given data is like this&lt;/P&gt;&lt;P&gt;EMP Sales&lt;/P&gt;&lt;P&gt;Group1 1000&lt;/P&gt;&lt;P&gt;E1 150&lt;/P&gt;&lt;P&gt;E2 200&lt;/P&gt;&lt;P&gt;E3 100&lt;/P&gt;&lt;P&gt;E4 250&lt;/P&gt;&lt;P&gt;E5 &amp;nbsp;&lt;/P&gt;&lt;P&gt;E6 &amp;nbsp;&lt;/P&gt;&lt;P&gt;E7 &amp;nbsp;&lt;/P&gt;&lt;P&gt;Uder Group1 - total 7 Emp are there. we need to show sales. But&lt;/P&gt;&lt;P&gt;Last 3 Employee sales details are missed we need to show last 3 employees sales as 'Others'&lt;/P&gt;&lt;P&gt;Others Sales = Group1 - (E1+E2+E3+E4)&lt;/P&gt;&lt;P&gt;I want to show in Qlik&amp;nbsp; EMP Sales Group1 1000 E1 150 E2 200 E3 100 E4 250 Other 300&lt;/P&gt;&lt;P&gt;&amp;nbsp;300 = 1000-(150+200+100+250). I want achieve this through backend only.&lt;/P&gt;&lt;!--     end #ae_app     --&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;!--  end #ae_app  --&gt;</description>
      <pubDate>Mon, 28 Apr 2025 12:46:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Subtraction-in-Script-part/m-p/2516009#M105738</guid>
      <dc:creator>MMK</dc:creator>
      <dc:date>2025-04-28T12:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subtraction in Script part</title>
      <link>https://community.qlik.com/t5/App-Development/Subtraction-in-Script-part/m-p/2516078#M105746</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/242264"&gt;@MMK&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This might be a bit of a long way around, but it works. I also added more groups as this might not always be only 1 group in the data... I wasn't sure.&lt;/P&gt;&lt;P&gt;Here is the resulting Table&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JandreKillianRIC_0-1745911760783.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/180008i30AAF0804BF95421/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JandreKillianRIC_0-1745911760783.png" alt="JandreKillianRIC_0-1745911760783.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the script&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;////////////////////////////////////////////////////////////////////////////////
// Load inline with more than one group as this might be what is in the data and not
// just in the sample provided 
////////////////////////////////////////////////////////////////////////////////


TmpSales:
Load 
	*, 
    RecNo() as SortingTmp; // Adding this for the sorting in the front end
Load * Inline [
EMP,Sales
Group1,1000
E1,150
E2,200
E3,100
E4,250
E5,
E6,
E7,
Group2,1420
E1,150
E2,200
E3,100
E4,250
E5,
Group3,1970
E1,150
E2,200
E3,100
E4,250
E5,500
E6,600
E7,
E8,
E9,
];

////////////////////////////////////////////////////////////////////////////////
// Define group level per individual line item
////////////////////////////////////////////////////////////////////////////////

TmpSales2:
Load 
	SortingTmp,
	EMP, 
    IF(Sales = 0 or Len(Trim(Sales)) = 0, 0, Sales) as Sales, // Cleaning up the Sales for later
    IF(WildMatch(EMP, 'Group*'), 
    	EMP, Peek('GroupName')) as GroupName, // Getting the Group that the Sales belong to
    IF(WildMatch(EMP, 'Group*'), 
    	Sales, Peek('GroupSales')) as GroupSales // Adding the Group Totals as this is to be used later
Resident TmpSales; 

Drop Table TmpSales; 

////////////////////////////////////////////////////////////////////////////////
// Get totals per group (Excl the group values)
////////////////////////////////////////////////////////////////////////////////

GroupTotalsLineItems:
Left Join (TmpSales2)
Load 
	GroupName,  
    Sum(Sales) as TotalSales
Resident TmpSales2
Where Not WildMatch(EMP, 'Group*') // Excl the Group Value
Group By GroupName; 


////////////////////////////////////////////////////////////////////////////////
// Calculate the Others (Sales that are 0)
////////////////////////////////////////////////////////////////////////////////

TmpSales3:
Load 
    IF(Sales = 0, Peek('Sorting')+1, 
    	SortingTmp) as Sorting, // Fixing the sorting as we are grouping the Sales EMP where sales = 0
	EMP,
    IF(Sales = 0, 
    	'Others', 
        EMP) as ReportingEMP, 
    GroupName, 
    TotalSales, 
    GroupSales,
    Sales, 
    IF(Sales = 0 and Peek('ReportingEMP') &amp;lt;&amp;gt; 'Others', 
    	 GroupSales - TotalSales, 
        Sales) as ReportingSales
Resident TmpSales2
Order By SortingTmp;

Drop Table TmpSales2; 

////////////////////////////////////////////////////////////////////////////////
// Clean up table (Remove all 0's as this is catered for) 
////////////////////////////////////////////////////////////////////////////////

Sales:
NoConcatenate
Load 
	*
Resident TmpSales3
Where ReportingSales &amp;lt;&amp;gt; 0;

Drop Table TmpSales3; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards - Jandre&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;!--  
        Layout, Style or Voice Helpers
      --&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;!--  
        Compliance
      --&gt;&lt;DIV class=""&gt;&lt;!--   For autoSmartRem addNewWindowWarnings div is referenced in an aria-describedby   --&gt;&lt;DIV&gt;Opens in new window&lt;/DIV&gt;&lt;DIV&gt;PDF Download&lt;/DIV&gt;&lt;DIV&gt;Word Download&lt;/DIV&gt;&lt;DIV&gt;Excel Download&lt;/DIV&gt;&lt;DIV&gt;PowerPoint Download&lt;/DIV&gt;&lt;DIV&gt;Document Download&lt;/DIV&gt;&lt;/DIV&gt;&lt;!--  
        Versioning Control Panel if versioning = true !
      --&gt;&lt;!--  
        Launcher
      --&gt;&lt;!--   Toolbar   --&gt;&lt;!--  
        Site Menu
      --&gt;&lt;!--  
        Generic Aria Live message container
      --&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;!--   Symbol definitions   --&gt;&lt;/DIV&gt;&lt;!--   end #ae_app   --&gt;</description>
      <pubDate>Tue, 29 Apr 2025 07:30:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Subtraction-in-Script-part/m-p/2516078#M105746</guid>
      <dc:creator>JandreKillianRIC</dc:creator>
      <dc:date>2025-04-29T07:30:59Z</dc:date>
    </item>
  </channel>
</rss>

