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
Hooi_livenow
Frequent Visitor

How to caculate the add value in one column

Dear all, 

 

I have data as per the screenshot below. And I would like to create a new column with the total value of this month + last month Example the total receivable in 12/1/2021+ Total Receivable 11/1/2021. How can I do that in Power Query editor or using Dax formula? 

 

Hooi_livenow_0-1659590869624.png

 

Thanks in advance~ 

 

Regards, Hooi 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TczBDQAhCETRXjibuDOI2oux/zYkcGCvLz//HAE6Oj9CmizKbU4sMiSl0EU1hCXcIfqTbEbJyo+VTAuZJXC5Dw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document Date" = _t, #"Total Receiveable by Month" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document Date", type date}, {"Total Receiveable by Month", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Total", each if [Index]=0 then [Total Receiveable by Month] else [Total Receiveable by Month]+#"Added Index"[Total Receiveable by Month]{[Index]-1}, type number),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 If performance is a consideration

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TczBDQAhCETRXjibuDOI2oux/zYkcGCvLz//HAE6Oj9CmizKbU4sMiSl0EU1hCXcIfqTbEbJyo+VTAuZJXC5Dw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document Date" = _t, #"Total Receiveable by Month" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document Date", type date}, {"Total Receiveable by Month", Int64.Type}}),
    BuffList = #"Changed Type"[Total Receiveable by Month],
    GenListOfTotal = List.Generate(()=>[x=BuffList{0},y=0], each [y]<List.Count(BuffList), each [y=[y]+1, x=BuffList{[y]}+BuffList{y}], each [x]),
    Result = Table.FromColumns(Table.ToColumns(#"Changed Type") & {GenListOfTotal},Table.ColumnNames(#"Changed Type")&{"Total"})
in
    Result

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TczBDQAhCETRXjibuDOI2oux/zYkcGCvLz//HAE6Oj9CmizKbU4sMiSl0EU1hCXcIfqTbEbJyo+VTAuZJXC5Dw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document Date" = _t, #"Total Receiveable by Month" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document Date", type date}, {"Total Receiveable by Month", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Total", each if [Index]=0 then [Total Receiveable by Month] else [Total Receiveable by Month]+#"Added Index"[Total Receiveable by Month]{[Index]-1}, type number),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 If performance is a consideration

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TczBDQAhCETRXjibuDOI2oux/zYkcGCvLz//HAE6Oj9CmizKbU4sMiSl0EU1hCXcIfqTbEbJyo+VTAuZJXC5Dw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document Date" = _t, #"Total Receiveable by Month" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document Date", type date}, {"Total Receiveable by Month", Int64.Type}}),
    BuffList = #"Changed Type"[Total Receiveable by Month],
    GenListOfTotal = List.Generate(()=>[x=BuffList{0},y=0], each [y]<List.Count(BuffList), each [y=[y]+1, x=BuffList{[y]}+BuffList{y}], each [x]),
    Result = Table.FromColumns(Table.ToColumns(#"Changed Type") & {GenListOfTotal},Table.ColumnNames(#"Changed Type")&{"Total"})
in
    Result

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.