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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Lebron45
Helper I
Helper I

cumulative sum

Hello I would like to obtain this result

I want to make a cumulative sum each in relation to my previous value, my base value is that of B

indexAB
11015
220=15+20=35
330=35+30=65
440=65+40=105


Result:

IndexAB
11015
22035
33065
440105

earlier doesn't work
B =
IF (
    test[Index] = 1
    test[B]
    CALCULATE(
        SUMX(
            FILTER(
                test,
               test[Index] <= EARLIER(test[Index])  
            ),
            test[B]  
        )
    )
)
thank you for your feedback
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Lebron45 ,


powerbidev123's reply could return the result you want. However if A1 is not 10, it will not work. I don't suggest you to use EARLIER() function, it may cause bad performance if you have large size of data.

You can also try my code to create a calculated column.

B =
VAR _B1 = 15
VAR _CurrentIndex = 'Table'[index]
RETURN
    IF (
        'Table'[index] = 1,
        _B1,
        _B1
            + CALCULATE (
                SUM ( 'Table'[A] ),
                FILTER ( 'Table', 'Table'[index] > 1 && 'Table'[index] <= _CurrentIndex )
            )
    )

Result is as below.

vrzhoumsft_0-1733191127068.png

 

Best Regards,
Rico Zhou

 

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

7 REPLIES 7
v-rzhou-msft
Community Support
Community Support

Hi @Lebron45 ,


powerbidev123's reply could return the result you want. However if A1 is not 10, it will not work. I don't suggest you to use EARLIER() function, it may cause bad performance if you have large size of data.

You can also try my code to create a calculated column.

B =
VAR _B1 = 15
VAR _CurrentIndex = 'Table'[index]
RETURN
    IF (
        'Table'[index] = 1,
        _B1,
        _B1
            + CALCULATE (
                SUM ( 'Table'[A] ),
                FILTER ( 'Table', 'Table'[index] > 1 && 'Table'[index] <= _CurrentIndex )
            )
    )

Result is as below.

vrzhoumsft_0-1733191127068.png

 

Best Regards,
Rico Zhou

 

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

 

powerbidev123
Responsive Resident
Responsive Resident

Hi @Lebron45 , Let me know if this helps

B =
5 + SUMX(
    FILTER(
        'Table (3)',
        'Table (3)'[Index] <= EARLIER('Table (3)'[Index])
    ),
    'Table (3)'[A]
)
bhanu_gautam
Super User
Super User

@Lebron45 , Try using 

Cumulative B =
CALCULATE(
SUM(test[A]),
FILTER(
ALL(test),
test[Index] <= MAX(test[Index])
)
) + MIN(test[B])

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Lebron45_0-1733148630962.png

 

@Lebron45 , Try using

 

B =
IF (
test[Index] = 1,
test[B],
test[A] +
CALCULATE(
MAX(test[B]),
FILTER(
test,
test[Index] = EARLIER(test[Index]) - 1
)
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam I already tried, but it doesn't work, "earlier" shows me an error

Lebron45_1-1733150908701.png

 

hi @bhanu_gautam thank you for your feedback, but I would like to fill my column B from the second and each time by making my value from the current line of my column A + my last value from the previous line of column B

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors