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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Power Query to calculate based on the previous values

Hi All, 

 

I am struggling with power query for hours to replicate the below logic in the picture. I have diffrent assets with serial numbers that has Total_BAV for the first year. what I need to calculate is the replacemnet amounts based on the Total_BAV which changing each year moving forward with the inflation rates. 

abahloul_0-1673715891816.png

below is the expected return values 

abahloul_1-1673716164285.png

Any Support is really appreicated! 

1 ACCEPTED SOLUTION
jgordon11
Resolver II
Resolver II

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(
        "jdJLDoAgDATQu7gmpvSTeBfCDYg77y/YlYCMJKQNM4u3IKUtbuG5TMxtsFE7daW9PeXgHfaO1HFepQy5eK5fuXpus5zfhugEGjorAwMDA4N0hmNiEGAQYBBg0B8GBQYFBgUG6/6DTgwGDAYMtjLkGw==", 
        BinaryEncoding.Base64), Compression.Deflate)), type table [#"Sr. No", Year, #"Actual Year", Total_BAV, Inflation_Rates]),
    ChangeType = Table.TransformColumnTypes(Source,{{"Sr. No", type text}, {"Year", Int64.Type}, {"Actual Year", Int64.Type}, {"Total_BAV", type number}, {"Inflation_Rates", type number}}),
    tcn = Table.ColumnNames(ChangeType) & {"Replacement"},
    Group = Table.Group(ChangeType, {"Sr. No"}, {"All", each 
            let lst = List.Accumulate(List.Skip(_[Inflation_Rates]), {_[Total_BAV]{0}}, (s,c)=> s & {List.Last(s)*(1+c)} )
            in Table.FromColumns(Table.ToColumns(_) & {lst}, tcn)
    }),
    Expand = Table.ExpandTableColumn(Group, "All", List.Skip(tcn))
in  
    Expand

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Excellent !  , Works like a charm. Thanks 

jgordon11
Resolver II
Resolver II

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(
        "jdJLDoAgDATQu7gmpvSTeBfCDYg77y/YlYCMJKQNM4u3IKUtbuG5TMxtsFE7daW9PeXgHfaO1HFepQy5eK5fuXpus5zfhugEGjorAwMDA4N0hmNiEGAQYBBg0B8GBQYFBgUG6/6DTgwGDAYMtjLkGw==", 
        BinaryEncoding.Base64), Compression.Deflate)), type table [#"Sr. No", Year, #"Actual Year", Total_BAV, Inflation_Rates]),
    ChangeType = Table.TransformColumnTypes(Source,{{"Sr. No", type text}, {"Year", Int64.Type}, {"Actual Year", Int64.Type}, {"Total_BAV", type number}, {"Inflation_Rates", type number}}),
    tcn = Table.ColumnNames(ChangeType) & {"Replacement"},
    Group = Table.Group(ChangeType, {"Sr. No"}, {"All", each 
            let lst = List.Accumulate(List.Skip(_[Inflation_Rates]), {_[Total_BAV]{0}}, (s,c)=> s & {List.Last(s)*(1+c)} )
            in Table.FromColumns(Table.ToColumns(_) & {lst}, tcn)
    }),
    Expand = Table.ExpandTableColumn(Group, "All", List.Skip(tcn))
in  
    Expand

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors