Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8975

Re: Need a Logic for balance

$
0
0

Hello Madhu,

 

I think the logic has to be implemented in different way to resolve the issues listed.

 

Step 1: Create new output field Rank_New = decode(RANK = 1, 1, 2). Here, we are keeping the records other than rank 1 to new group

 

Step 2: Apply sort or SSN, Rank_New and then Rank

 

Step 3: Output of Step 2 is connected to 2 query transforms. No need to apply any filter.

 

Step 4: Join previous 2 query transforms (Inner join). Use below join criteria. Get SSN, Rank, Balance from Query_Current. Get Paid Amt from Query_Old

Query_Old.SSN = Query_Current.SSN AND

Query_Current.RANK_NEW= Query_Old.RANK_NEW AND

Query_Old.RANK <= Query_Current.RANK

 

Step 5: Aggregate Paid Amount. Sum(Paid_amt) and all other fields in group by clause

 

Step 6: New_balance = decode(rank = 1, balance, balance - paid_amt)

 

Step 7: Create new field for calculating balance, balance_inter = previous_row_value(New_balance)

 

Step 8: Balance = decode(rank = 1, balance, balance_inter)

 

Balance.PNG

Hope the above steps will resolve your issue. If you are getting incorrect values in new balance and balance, apply sort on ssn and rank at the step 5.


Viewing all articles
Browse latest Browse all 8975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>