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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
baravo
Helper I
Helper I

How to sum diffently positioned rows in various columns?

Hi,  I need to calculate a column with the closing balance of each day. The closing balance becomes the opening balance for the next day.

 

Opening balance + Variables_SUM = Closing balance

 

In Excel, there are 2 steps to calculate this column:

1. First day (I3): Sum the opening balance with the Variables_SUM from that day - this gets the Closing balance of the first day (in my example, it's 595.324)

2. Second day on (I4 and rest): Sum the closing balance of the first day with the Variables_SUM from the second day (see image).

 

Step 1

baravo_1-1619173365315.png

 

Step 2

baravo_2-1619173488356.png

 

I post this table as an example in case you want to replicate it in Power BI.

I really appreciate your help. Thank you!

 

  Variables    How to get this in Power BI?
Date VAR1 - minus  VAR2 - minus  VAR3 - plus  VAR4 - minus  Opening balance 1st day  Closing balance 1st day  Variables_SUM  Cash flow calculation 
21/04/2021                                282.335                           -            446.302                55.808                                      487.165                                    595.324                      108.159                               595.324
22/04/2021                                912.919                           -            397.557                55.808                                                  -                                                 -  -                     571.170                                 24.154
23/04/2021                                187.327               200.000          400.891                55.808                                                  -                                                 -  -                       42.244-                                18.090
24/04/2021                                            -                             -              21.918                         -                                                    -                                                 -                          21.918                                   3.828
25/04/2021                                            -                             -              28.059                         -                                                    -                                                 -                          28.059                                 31.887
26/04/2021                                111.859                           -            599.218                55.808                                                  -                                                 -                        431.552                               463.438
27/04/2021                                160.553                           -            608.805                55.808                                                  -                                                 -                        392.444                               855.882
28/04/2021                                442.175                           -            446.302                55.808                                                  -                                                 -  -                       51.681                               804.201
29/04/2021                                723.623                           -            397.557                55.808                                                  -                                                 -  -                     381.874                               422.327
30/04/2021                                259.049                           -            400.891                55.808                                                  -                                                 -                          86.034                               508.361
01/05/2021                                            -                             -              21.918                         -                                                    -                                                 -                          21.918                               530.279
02/05/2021                                            -                             -              28.059                         -                                                    -                                                 -                          28.059                               558.338
03/05/2021                                   84.049                           -            599.218                55.808                                                  -                                                 -                        459.362                             1.017.699
04/05/2021                                   11.620                           -            608.805                55.808                                                  -                                                 -                        541.377                             1.559.076
05/05/2021                                178.000                           -            446.302                55.808                                                  -                                                 -                        212.494                             1.771.569
06/05/2021                                            -                 750.000          397.557                55.808                                                  -                                                 -  -                     408.251                             1.363.318
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @baravo ,

 

Based on your description, you can create a calculated column as follows.

Cash flow calculation =
MAX ( 'Test'[Opening balance 1st day] )
    + SUMX (
        FILTER ( ALL ( 'Test' ), [Date] <= EARLIER ( Test[Date] ) ),
        [Variables_SUM]
    )

Result:

v-yuaj-msft_0-1619490766898.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @baravo ,

 

Based on your description, you can create a calculated column as follows.

Cash flow calculation =
MAX ( 'Test'[Opening balance 1st day] )
    + SUMX (
        FILTER ( ALL ( 'Test' ), [Date] <= EARLIER ( Test[Date] ) ),
        [Variables_SUM]
    )

Result:

v-yuaj-msft_0-1619490766898.png

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@baravo , You have to create a measure like

 

Sumx(all(Table), [Opening balance]) + CALCULATE(Sumx(Table,[Var3] -[Var2] -[Var1] -[Var4]) ,filter(allselected(Table),Table[Date] <=max(Table[Date])))

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.