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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
JLambs20
Helper III
Helper III

Create a column that subtracts a value from the previous row until 0

I need to create the highlighted yellow column in this screenshot (Excel) but in Power BI. The column starts with a known value (story points), subtracts the points per day value, which results in a number and then that "formula" needs repeated down until the answer is 0. Help!

 

Thanks in advance everyone!

 

Screenshot 2021-03-16 145740.png

1 ACCEPTED SOLUTION
jameszhang0805
Resolver IV
Resolver IV

Please try the below code :

Balance = 
VAR _MaxIndex =
    MAX ( 'Table'[Index] )
VAR _Table =
    ADDCOLUMNS (
        SUMMARIZE (
            'Table',
            'Table'[Index],
            'Table'[Total Points],
            'Table'[Points/Days]
        ),
        "@Cumulative", CALCULATE ( SUM ( 'Table'[Points/Days] ), 'Table'[Index] <= _MaxIndex )
    )
VAR _ResultTable =
    ADDCOLUMNS (
        _Table,
        "@Balance",
            [Total Points] - [@Cumulative]
                + FIRSTNONBLANKVALUE ( 'Table'[Index], [Points/Days] )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[Index] ), SUMX ( _ResultTable, [@Balance] ) )

jameszhang0805_0-1615967059416.png

 

 

View solution in original post

1 REPLY 1
jameszhang0805
Resolver IV
Resolver IV

Please try the below code :

Balance = 
VAR _MaxIndex =
    MAX ( 'Table'[Index] )
VAR _Table =
    ADDCOLUMNS (
        SUMMARIZE (
            'Table',
            'Table'[Index],
            'Table'[Total Points],
            'Table'[Points/Days]
        ),
        "@Cumulative", CALCULATE ( SUM ( 'Table'[Points/Days] ), 'Table'[Index] <= _MaxIndex )
    )
VAR _ResultTable =
    ADDCOLUMNS (
        _Table,
        "@Balance",
            [Total Points] - [@Cumulative]
                + FIRSTNONBLANKVALUE ( 'Table'[Index], [Points/Days] )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[Index] ), SUMX ( _ResultTable, [@Balance] ) )

jameszhang0805_0-1615967059416.png

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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