Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
amdbabu
Contributor
Contributor

Calculating Cumulative Revenue in Load Script

Hi,

I have a table with account id, bill date and bill amount with historical data. How do I add a new field called cumulative amount which will add amount from previous months ad current bill amount (Running Total). This needs to be grouped by account id.

Thank you

Labels (1)
1 Solution

Accepted Solutions
brunobertels
Master
Master

Hi 

something like that 

Temp:

load

rowno() as Rowkey,

Date,

Account_Id, 

bill_amount

from your source;

Final:

load

*

if(Rowkey=1,bill_amount, if(peek('Account_Id')<> Account_Id,bill_amount, bill_amount +peek('bill_amount_cumul') ) ) as bill_amount_cumul

resident Temp order by Date,Account_Id ;

drop table Temp;

 

 

View solution in original post

2 Replies
brunobertels
Master
Master

Hi 

something like that 

Temp:

load

rowno() as Rowkey,

Date,

Account_Id, 

bill_amount

from your source;

Final:

load

*

if(Rowkey=1,bill_amount, if(peek('Account_Id')<> Account_Id,bill_amount, bill_amount +peek('bill_amount_cumul') ) ) as bill_amount_cumul

resident Temp order by Date,Account_Id ;

drop table Temp;

 

 

amdbabu
Contributor
Contributor
Author

Yeah I tried this but it doesn't seem to work.  I changed the order by as account, date and it worked ! Thank you !