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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Running Sum Calculation

I have a column like that, i want to create new column like that.

 

Column1         New Column

       0                          0

       1                          4

       1                          3

       1                          2

       1                          1

       0                          0

       0                          0

       1                          2

       1                          1

       0                          0

       1                          3

       1                          2
       1                          1
       0                          0       

if the value in Column1 is 1, then the value after that will be 0. It will write the sum to the column with the first 1 value and reduce the next values ​​by 1.

Sorry for my english, it was hard to explain it 🙂

 

 

 

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

First add an Index Column from Query Editor

 

Then you can use this calculated column

 

New_ =
VAR FindNextZeroIndex =
    MINX (
        TOPN (
            1,
            FILTER ( Table1, [Index] > EARLIER ( [Index] ) && [Column1 ] = 0 ),
            [Index], ASC
        ),
        [Index]
    )
RETURN
    IF (
        [Column1 ] = 1,
        CALCULATE (
            SUM ( Table1[Column1 ] ),
            FILTER (
                Table1,
                Table1[Index] >= EARLIER ( Table1[Index] )
                    && Table1[Index] < FindNextZeroIndex
            )
        ),
        0
    )

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

First add an Index Column from Query Editor

 

Then you can use this calculated column

 

New_ =
VAR FindNextZeroIndex =
    MINX (
        TOPN (
            1,
            FILTER ( Table1, [Index] > EARLIER ( [Index] ) && [Column1 ] = 0 ),
            [Index], ASC
        ),
        [Index]
    )
RETURN
    IF (
        [Column1 ] = 1,
        CALCULATE (
            SUM ( Table1[Column1 ] ),
            FILTER (
                Table1,
                Table1[Index] >= EARLIER ( Table1[Index] )
                    && Table1[Index] < FindNextZeroIndex
            )
        ),
        0
    )

@Anonymous

 

See file attached as well

 

running.png

Anonymous
Not applicable

Thanks @Zubair_Muhammad absolutely working

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors