Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
naveen73
Helper III
Helper III

Value in the previous row

Hi All,

I am trying to achieve something with Power Query. I think it is best to describe my problem with a screen shot.

I want to calculate interest using the end principal of the previous month (cell J8). See screenshot 1.

naveen73_0-1684184033250.png

 

         

The end principal is calculated by taking the previous principal and subtracting the interest and payment. See screenshot 2.

naveen73_1-1684184033256.png

 

thanks,

 

Naveen

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0MACSliCWUqxOtJIRkAVEJnqmcCFjmJARXMgEKgQXMIUIGOuZQ4RiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, #"Begin Principal" = _t, Interest = _t, Payment = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", Int64.Type}, {"Begin Principal", Currency.Type}, {"Interest", Currency.Type}, {"Payment", Currency.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "End Principal", each List.Accumulate({1..[Month]},#"Changed Type"[Begin Principal]{0},(state,current)=>state-#"Changed Type"[Interest]{current-1}-#"Changed Type"[Payment]{current-1}))
in
    #"Added Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0MACSliCWUqxOtJIRkAVEJnqmcCFjmJARXMgEKgQXMIUIGOuZQ4RiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, #"Begin Principal" = _t, Interest = _t, Payment = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", Int64.Type}, {"Begin Principal", Currency.Type}, {"Interest", Currency.Type}, {"Payment", Currency.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "End Principal", each List.Accumulate({1..[Month]},#"Changed Type"[Begin Principal]{0},(state,current)=>state-#"Changed Type"[Interest]{current-1}-#"Changed Type"[Payment]{current-1}))
in
    #"Added Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Thanks so much for this. I think it is doing the trick!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors