<?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: Average Daily Balance in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1704213#M63891</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you go:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FactData:
LOAD * INLINE [
    cust_no, trxn_date, balance, ADB_Date, ADB, Current_ADB
    10031, 1-Jan-20, 0, 1-Jan-20, 0, 890.33
    10031, 2-Jan-20, 100, 2-Jan-20, 50, 890.33
    10031, 3-Jan-20, 345, 3-Jan-20, 148.3, 890.33
    10031, 4-Jan-20, 50, 4-Jan-20, 123.75, 890.33
    10031, 5-Jan-20, 0, 5-Jan-20, 99, 890.33
    10031, 6-Jan-20, 0, 6-Jan-20, 82.5, 890.33
    10031, 7-Jan-20, 560, 7-Jan-20, 150.71, 890.33
    10031, 8-Jan-20, 400, 8-Jan-20, 181.88, 890.33
    10031, 9-Jan-20, 800, 9-Jan-20, 250.56, 890.33
    10031, 10-Jan-20, 1200, 10-Jan-20, 345.5, 890.33
    10031, 11-Jan-20, 1500, 11-Jan-20, 450.45, 890.33
    10031, 12-Jan-20, 1700, 12-Jan-20, 554.58, 890.33
    10031, 13-Jan-20, 0, 13-Jan-20, 511.92, 890.33
    10031, 14-Jan-20, 3200, 14-Jan-20, 703.93, 890.33
    10031, 15-Jan-20, 3500, 15-Jan-20, 890.33, 890.33
];

Results_temp:
NoConcatenate
LOAD
	cust_no,
	Date(Date#(trxn_date, 'D-MMM-YY'), 'DD-MM-YYYY') as TRXN_Date,
	MonthName(Date#(trxn_date, 'D-MMM-YY')) as TRXN_Month,
	Sum(balance) as DailyBalance
Resident FactData
GROUP BY
	cust_no,
	Date(Date#(trxn_date, 'D-MMM-YY'), 'DD-MM-YYYY'),
	MonthName(Date#(trxn_date, 'D-MMM-YY'))
;

DROP TABLE FactData;

Results_temp2:
NoConcatenate
LOAD
	cust_no,
	TRXN_Date,
	TRXN_Month,
	DailyBalance,
	IF((cust_no &amp;lt;&amp;gt; peek(cust_no,-1)) 
		OR
		(TRXN_Month&amp;lt;&amp;gt;peek(TRXN_Month,-1)),
		1, peek(SubCount,-1)+1) as SubCount,
		
	IF((cust_no &amp;lt;&amp;gt; peek(cust_no,-1)) 
		OR
		(TRXN_Month&amp;lt;&amp;gt;peek(TRXN_Month,-1)),
		DailyBalance, DailyBalance+ peek(AccumulatedBalance,-1)) as AccumulatedBalance
Resident Results_temp
Order BY
cust_no ASC, TRXN_Date ASC
;

DROP TABLE Results_temp;

Results:
NoConcatenate
LOAD
	cust_no,
	TRXN_Date,
	TRXN_Month,
	DailyBalance,
	SUM(AccumulatedBalance)/Sum(SubCount) as AverageDailyBalance
Resident Results_temp2
GROUP BY
	cust_no,
	TRXN_Date,
	TRXN_Month,
	DailyBalance
;

DROP TABLE Results_temp2;

CurrentBalance:
NoConcatenate
LOAD
	cust_no,
	TRXN_Date,
	AverageDailyBalance
Resident Results
;

INNER JOIN(CurrentBalance)
LOAD DISTINCT
	cust_no,
	Max(TRXN_Date) as TRXN_Date
RESIDENT CurrentBalance
GROUP BY
	cust_no
;	
	
LEFT JOIN(Results)
LOAD DISTINCT
	cust_no,
	AverageDailyBalance as CurrentBalance
Resident CurrentBalance
;

DROP TABLE CurrentBalance;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code is plug-and-play.&lt;/P&gt;&lt;P&gt;Let me know if you have questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;S.T.&lt;/P&gt;</description>
    <pubDate>Thu, 21 May 2020 16:32:11 GMT</pubDate>
    <dc:creator>Stoyan_Terziev</dc:creator>
    <dc:date>2020-05-21T16:32:11Z</dc:date>
    <item>
      <title>Average Daily Balance</title>
      <link>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1704205#M63890</link>
      <description>&lt;P&gt;Hi Everyone!&lt;/P&gt;&lt;P&gt;I don't know if I search the community enough but PLEASE help or advise on how to get the &lt;STRONG&gt;AVERAGE DAILY BALANCE&amp;nbsp;&lt;/STRONG&gt;in a transactional table.&lt;/P&gt;&lt;P&gt;For this I think I need 3 new fields in my table, kindly see below for the sample table with 1 customer record and the expected output in &lt;FONT color="#993300"&gt;&lt;STRONG&gt;bold and red fonts&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE width="405px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;cust_no&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;trxn_date&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;balance&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;&lt;FONT color="#993300"&gt;&lt;STRONG&gt;ADB_Date&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;&lt;FONT color="#993300"&gt;&lt;STRONG&gt;ADB&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;&lt;FONT color="#993300"&gt;&lt;STRONG&gt;Current_ADB&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;1-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;0&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;1-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;0&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;2-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;100&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;2-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;50&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;3-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;345&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;3-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;148.3&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;4-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;50&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;4-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;123.75&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;5-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;0&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;5-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;99&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;6-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;0&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;6-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;82.5&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;7-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;560&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;7-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;150.71&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;8-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;400&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;8-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;181.88&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="25px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="25px"&gt;9-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="25px"&gt;800&lt;/TD&gt;&lt;TD width="78px" height="25px"&gt;9-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="25px"&gt;250.56&lt;/TD&gt;&lt;TD width="98px" height="25px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="47px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="47px"&gt;10-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="47px"&gt;1200&lt;/TD&gt;&lt;TD width="78px" height="47px"&gt;10-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="47px"&gt;345.5&lt;/TD&gt;&lt;TD width="98px" height="47px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="47px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="47px"&gt;11-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="47px"&gt;1500&lt;/TD&gt;&lt;TD width="78px" height="47px"&gt;11-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="47px"&gt;450.45&lt;/TD&gt;&lt;TD width="98px" height="47px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="47px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="47px"&gt;12-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="47px"&gt;1700&lt;/TD&gt;&lt;TD width="78px" height="47px"&gt;12-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="47px"&gt;554.58&lt;/TD&gt;&lt;TD width="98px" height="47px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="47px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="47px"&gt;13-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="47px"&gt;0&lt;/TD&gt;&lt;TD width="78px" height="47px"&gt;13-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="47px"&gt;511.92&lt;/TD&gt;&lt;TD width="98px" height="47px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="47px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="47px"&gt;14-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="47px"&gt;3200&lt;/TD&gt;&lt;TD width="78px" height="47px"&gt;14-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="47px"&gt;703.93&lt;/TD&gt;&lt;TD width="98px" height="47px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="65px" height="19px"&gt;10031&lt;/TD&gt;&lt;TD width="76px" height="19px"&gt;15-Jan-20&lt;/TD&gt;&lt;TD width="64px" height="19px"&gt;3500&lt;/TD&gt;&lt;TD width="78px" height="19px"&gt;15-Jan-20&lt;/TD&gt;&lt;TD width="55px" height="19px"&gt;890.33&lt;/TD&gt;&lt;TD width="98px" height="19px"&gt;890.33&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I plan to do this in the script and guessing I could use peek here? but I am really in the dark on how to maximize that function with this requirement. Really appreciate your help! Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 02:21:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1704205#M63890</guid>
      <dc:creator>Badzreyes00</dc:creator>
      <dc:date>2024-11-16T02:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Average Daily Balance</title>
      <link>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1704213#M63891</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you go:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FactData:
LOAD * INLINE [
    cust_no, trxn_date, balance, ADB_Date, ADB, Current_ADB
    10031, 1-Jan-20, 0, 1-Jan-20, 0, 890.33
    10031, 2-Jan-20, 100, 2-Jan-20, 50, 890.33
    10031, 3-Jan-20, 345, 3-Jan-20, 148.3, 890.33
    10031, 4-Jan-20, 50, 4-Jan-20, 123.75, 890.33
    10031, 5-Jan-20, 0, 5-Jan-20, 99, 890.33
    10031, 6-Jan-20, 0, 6-Jan-20, 82.5, 890.33
    10031, 7-Jan-20, 560, 7-Jan-20, 150.71, 890.33
    10031, 8-Jan-20, 400, 8-Jan-20, 181.88, 890.33
    10031, 9-Jan-20, 800, 9-Jan-20, 250.56, 890.33
    10031, 10-Jan-20, 1200, 10-Jan-20, 345.5, 890.33
    10031, 11-Jan-20, 1500, 11-Jan-20, 450.45, 890.33
    10031, 12-Jan-20, 1700, 12-Jan-20, 554.58, 890.33
    10031, 13-Jan-20, 0, 13-Jan-20, 511.92, 890.33
    10031, 14-Jan-20, 3200, 14-Jan-20, 703.93, 890.33
    10031, 15-Jan-20, 3500, 15-Jan-20, 890.33, 890.33
];

Results_temp:
NoConcatenate
LOAD
	cust_no,
	Date(Date#(trxn_date, 'D-MMM-YY'), 'DD-MM-YYYY') as TRXN_Date,
	MonthName(Date#(trxn_date, 'D-MMM-YY')) as TRXN_Month,
	Sum(balance) as DailyBalance
Resident FactData
GROUP BY
	cust_no,
	Date(Date#(trxn_date, 'D-MMM-YY'), 'DD-MM-YYYY'),
	MonthName(Date#(trxn_date, 'D-MMM-YY'))
;

DROP TABLE FactData;

Results_temp2:
NoConcatenate
LOAD
	cust_no,
	TRXN_Date,
	TRXN_Month,
	DailyBalance,
	IF((cust_no &amp;lt;&amp;gt; peek(cust_no,-1)) 
		OR
		(TRXN_Month&amp;lt;&amp;gt;peek(TRXN_Month,-1)),
		1, peek(SubCount,-1)+1) as SubCount,
		
	IF((cust_no &amp;lt;&amp;gt; peek(cust_no,-1)) 
		OR
		(TRXN_Month&amp;lt;&amp;gt;peek(TRXN_Month,-1)),
		DailyBalance, DailyBalance+ peek(AccumulatedBalance,-1)) as AccumulatedBalance
Resident Results_temp
Order BY
cust_no ASC, TRXN_Date ASC
;

DROP TABLE Results_temp;

Results:
NoConcatenate
LOAD
	cust_no,
	TRXN_Date,
	TRXN_Month,
	DailyBalance,
	SUM(AccumulatedBalance)/Sum(SubCount) as AverageDailyBalance
Resident Results_temp2
GROUP BY
	cust_no,
	TRXN_Date,
	TRXN_Month,
	DailyBalance
;

DROP TABLE Results_temp2;

CurrentBalance:
NoConcatenate
LOAD
	cust_no,
	TRXN_Date,
	AverageDailyBalance
Resident Results
;

INNER JOIN(CurrentBalance)
LOAD DISTINCT
	cust_no,
	Max(TRXN_Date) as TRXN_Date
RESIDENT CurrentBalance
GROUP BY
	cust_no
;	
	
LEFT JOIN(Results)
LOAD DISTINCT
	cust_no,
	AverageDailyBalance as CurrentBalance
Resident CurrentBalance
;

DROP TABLE CurrentBalance;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code is plug-and-play.&lt;/P&gt;&lt;P&gt;Let me know if you have questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;S.T.&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 16:32:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1704213#M63891</guid>
      <dc:creator>Stoyan_Terziev</dc:creator>
      <dc:date>2020-05-21T16:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Average Daily Balance</title>
      <link>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1704303#M63892</link>
      <description>&lt;P&gt;Hi Stoyan,&lt;/P&gt;&lt;P&gt;This is reallyyyy cool. Thank you SO much! btw, this works great but would you mind explaining to me why it is partitioned monthly? I am hoping for a daily average from the start up to the current date and upon initial testing it resets the averaging in each month, so it's more like Average Monthly Daily Balance? Thank youuu!!!&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 06:49:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1704303#M63892</guid>
      <dc:creator>Badzreyes00</dc:creator>
      <dc:date>2020-05-22T06:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Average Daily Balance</title>
      <link>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1705125#M63893</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;Yeah, indeed it's monthly accumulation.&amp;nbsp;I though you are using this for accumulation for a monthly discount or another similar accounting principle.&lt;/P&gt;&lt;P&gt;If you need an all-time balance, just remove this part everywhere you see it:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;OR
		(TRXN_Month&amp;lt;&amp;gt;peek(TRXN_Month,-1))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Stoyan&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 09:58:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1705125#M63893</guid>
      <dc:creator>Stoyan_Terziev</dc:creator>
      <dc:date>2020-05-26T09:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Average Daily Balance</title>
      <link>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1705185#M63894</link>
      <description>&lt;P&gt;Hi Stoyan,&lt;/P&gt;&lt;P&gt;Yeah! I figured it out eventually and it works perfectly. Thank you so much!!!!!&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 12:17:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Average-Daily-Balance/m-p/1705185#M63894</guid>
      <dc:creator>Badzreyes00</dc:creator>
      <dc:date>2020-05-26T12:17:41Z</dc:date>
    </item>
  </channel>
</rss>

