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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
BCAdmin
New Member

Loop calculation

Hi All,

 

I'm trying to do this on Power BI, but I can't figure out the formula to do this. I want to use the previous calculated value from Column E to the next row and so on. Is it possible to be done on Power BI?

 

Below is the formula on Excel:

BCAdmin_1-1652215898223.png

 

The data value:

BCAdmin_2-1652215972356.png

 

Thank you!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BCAdmin ,

 

I have a test on amitchandak's code and I find that I won't return the result you want. Firstly, we need to add an Index column in Power Query if you only have month column in text format.

Your table will be like as below.

RicoZhou_0-1652420845380.png

Then add calculated columns in this table.

Column4 = 
VAR _START =
    CALCULATE ( SUM ( 'Table'[Column1] ), ALL ( 'Table' ) )
RETURN
    _START
        + SUMX (
            FILTER ( 'Table', 'Table'[Index] <= EARLIER ( 'Table'[Index] ) ),
            [Column2] - [Column3]
        )
New Column1 = 
VAR _PREVIOUS_COLUMN4 =
    CALCULATE (
        SUM ( 'Table'[Column4] ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    )
RETURN
    IF ( ISBLANK ( 'Table'[Column1] ), _PREVIOUS_COLUMN4, 'Table'[Column1] )

Result is as below.

RicoZhou_1-1652420892197.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

2 REPLIES 2
Anonymous
Not applicable

Hi @BCAdmin ,

 

I have a test on amitchandak's code and I find that I won't return the result you want. Firstly, we need to add an Index column in Power Query if you only have month column in text format.

Your table will be like as below.

RicoZhou_0-1652420845380.png

Then add calculated columns in this table.

Column4 = 
VAR _START =
    CALCULATE ( SUM ( 'Table'[Column1] ), ALL ( 'Table' ) )
RETURN
    _START
        + SUMX (
            FILTER ( 'Table', 'Table'[Index] <= EARLIER ( 'Table'[Index] ) ),
            [Column2] - [Column3]
        )
New Column1 = 
VAR _PREVIOUS_COLUMN4 =
    CALCULATE (
        SUM ( 'Table'[Column4] ),
        FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
    )
RETURN
    IF ( ISBLANK ( 'Table'[Column1] ), _PREVIOUS_COLUMN4, 'Table'[Column1] )

Result is as below.

RicoZhou_1-1652420892197.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.

 

 

amitchandak
Super User
Super User

@BCAdmin , Assume you have date or index column (add in power query)

 

You can create a new column

[Column1] - Sumx(filter(Table, [Date] <= earlier([date]) ), [Column2] -[Column3])

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.