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
phaum1967
Resolver I
Resolver I

Add a column for balance differences between two sequential periods.

Hi, this is my existing table, which aggregate excel files for each months. Excel files are cumulative data so I would like to have diffrence between two periods (last period).

Capture d’écran, le 2021-08-06 à 09.57.27.png

 I think it should be possible in langage m, I should order my table on Account and date but how can add a column which will do this:

if account row before is same value as actual row then calculalte row[Amount] - row before[Amount]

thanks

 

1 ACCEPTED SOLUTION
phaum1967
Resolver I
Resolver I

I find a solution with creating an index column and merge with my table with herself.

I find this to help me 

https://exceltown.com/en/tutorials/power-bi/powerbi-com-and-power-bi-desktop/power-bi-data-sources/p...

 

My code:

#"Lignes filtrées" = Table.SelectRows(#"Lignes triées", each ([Account] <> null)), #"Index ajouté" = Table.AddIndexColumn(#"Lignes filtrées", "Index", 1, 1, Int64.Type), #"Addition insérée" = Table.AddColumn(#"Index ajouté", "Addition", each [Index] + 1, type number), #"Requêtes fusionnées1" = Table.NestedJoin(#"Addition insérée", {"Index"}, #"Addition insérée", {"Addition"}, "Addition insérée", JoinKind.LeftOuter), #"Addition insérée développé" = Table.ExpandTableColumn(#"Requêtes fusionnées1", "Addition insérée", {"Account", "Amount"}, {"Addition insérée.Account", "Addition insérée.Amount"}), #"Colonnes supprimées" = Table.RemoveColumns(#"Addition insérée développé",{"Index", "Addition"}), #"Personnalisée ajoutée" = Table.AddColumn(#"Colonnes supprimées", "Variation", each if [Addition insérée.Account] <> null

View solution in original post

2 REPLIES 2
phaum1967
Resolver I
Resolver I

I find a solution with creating an index column and merge with my table with herself.

I find this to help me 

https://exceltown.com/en/tutorials/power-bi/powerbi-com-and-power-bi-desktop/power-bi-data-sources/p...

 

My code:

#"Lignes filtrées" = Table.SelectRows(#"Lignes triées", each ([Account] <> null)), #"Index ajouté" = Table.AddIndexColumn(#"Lignes filtrées", "Index", 1, 1, Int64.Type), #"Addition insérée" = Table.AddColumn(#"Index ajouté", "Addition", each [Index] + 1, type number), #"Requêtes fusionnées1" = Table.NestedJoin(#"Addition insérée", {"Index"}, #"Addition insérée", {"Addition"}, "Addition insérée", JoinKind.LeftOuter), #"Addition insérée développé" = Table.ExpandTableColumn(#"Requêtes fusionnées1", "Addition insérée", {"Account", "Amount"}, {"Addition insérée.Account", "Addition insérée.Amount"}), #"Colonnes supprimées" = Table.RemoveColumns(#"Addition insérée développé",{"Index", "Addition"}), #"Personnalisée ajoutée" = Table.AddColumn(#"Colonnes supprimées", "Variation", each if [Addition insérée.Account] <> null

amitchandak
Super User
Super User

@phaum1967 , add index column in power query

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

 

And this formula in dax

new column = [Amount]  -sumx(filter(Table , [index] = earlier([index]) -1),[Amount] )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.