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
paolomint
Helper III
Helper III

Rolling sum not from zero

Hi,

I'm workin on a running sum but this time I need something different:

As first step I built  a standard rolling sum:

 

ROLLING SUM  = CALCULATE(sum(SCADENZE[IMPORTO]), filter(ALLSELECTED(SCADENZE), SCADENZE[DATA SCADENZA]<=MAX(SCADENZE[DATA SCADENZA])))

 

It make a rolling sum of the positive/negative previsional variation in the bank account.

 

Now I need that the calculation not start from Zero but from the balance of the bank account

I made a measure to calculate the balance of the bank account at " time zero" and now I need to create a new measure to "say" to powerBi don't start from ZERO but from BANK_BALANCE

 

If I do this way:

= BANK_BALANCE + ROLLING SUM 

It doesn't work, It make the calculation for each day. I need that Bank balance is considered only for the first day.

An example can help me to better explain:

 

DATEBANK BALANCE*VARIATIONWRONG WRONG RIGHT 
25.09.201000+20020012001200
26.09.201000+40060014001600
30.09.201000-1005009001500
02.10.201000-700-200300800

* Bank Balance doesn't change because we are talking about future variation still not happened.

 

Thanks for yor help

 

 

1 ACCEPTED SOLUTION

Hi @paolomint ,

 

Maybe I understand what you mean.Based on your description, you have two tables, and you want the amount retained in the "bank" table as the starting amount of the "flow" table.

Try the measure.

ROLL_FLOW =
VAR base = [ROLL_BANK]
VAR end_date =
    CALCULATE ( MAX ( Bank[Date] ), ALL ( Bank ) )
RETURN
    IF (
        MAX ( FLOW[Date] ) > end_date,
        CALCULATE (
            SUM ( FLOW[VARIATION] ),
            FILTER ( ALLSELECTED ( FLOW ), FLOW[Date] <= MAX ( FLOW[Date] ) )
        ) + base,
        BLANK ()
    )

Sample .pbix 

 

Best Regards,
Liang
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

6 REPLIES 6
Fowmy
Super User
Super User

@paolomint 

Not very clear about the requirement.

Can you check this, Repace the XXXXX with the filed you need to net off

ROLLING SUM =
CALCULATE (
    SUM ( SCADENZE[IMPORTO] ) - SUM ( SCADENZE[xxxxx] ),
    FILTER (
        ALLSELECTED ( SCADENZE ),
        SCADENZE[DATA SCADENZA] <= MAX ( SCADENZE[DATA SCADENZA] )
    )
)

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hello @Fowmy

thank you for your quick response, it doesn't work,

Let me try to explain better with an example

Account balance transactions are in a table [BANK]

OPENING BALANCE: 1000

DateVariation
01.09.2020+300
02.09.2020-400
05.09.2020+800

BALANCE FINAL : 1700

To get the final balance I can use a classic RUNNING SUM formula:

ROLL_BANK: CALCULATE(sum(BANK[VARIATION]), filter(ALLSELECTED(BANK), BANK[DATE]<-MAX(BANK[DATE])))

--------------------------------------------------------------------------------------------------------------------------------------

In another table I have the future varation [FLOW]

DateVariation
25.09.2020+200
30.09.2020-500
05.10.2020- 400
ROLLING SUM- 700

RUNNING SUM Formula:

ROLL_FLOW: CALCULATE(sum(FLOW[VARIATION]), filter(ALLSELECTED(FLOW), FLOW[DATE]<-MAX(FLOW[DATE])))

---------------------------------------------------------------------------------------------------------------------------------------

I need a measure to get the following result:

DateVariation
25.09.20201900
30.09.20201400
05.10.20201000

Thank you for your help

Good bye

Hi,

In the BANK Table, it does not make sense to have a text entry (Opening balance) in a Date column.  There should be a Date in place of that text entry.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur

thanks for your reply, 

it was obvius, anyhow to avoid any misunerstanding, I modify the post.

Now the data are showed in the correct way, can you help me?

Thank you very much

Paolo 

Hi @paolomint ,

 

Maybe I understand what you mean.Based on your description, you have two tables, and you want the amount retained in the "bank" table as the starting amount of the "flow" table.

Try the measure.

ROLL_FLOW =
VAR base = [ROLL_BANK]
VAR end_date =
    CALCULATE ( MAX ( Bank[Date] ), ALL ( Bank ) )
RETURN
    IF (
        MAX ( FLOW[Date] ) > end_date,
        CALCULATE (
            SUM ( FLOW[VARIATION] ),
            FILTER ( ALLSELECTED ( FLOW ), FLOW[Date] <= MAX ( FLOW[Date] ) )
        ) + base,
        BLANK ()
    )

Sample .pbix 

 

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

Hi,

I still do not understand.  The Opening Balance has to as of a certain date.  So it should be a part of Table1 (first row) with a date assigned to 1000.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.