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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Conditional sum based on next row

Hi,

I have a requirement to calculate the total for the current row based on the next rows using DAX :

 

Data Set :

TypeValueRuleExpected Result
A10B + C +D +E250
B20C + D + E230
C50D + E180
D80E100
E100E100

 

How I can solve this .

Thanks.

1 ACCEPTED SOLUTION

@Anonymous , change like

new column = if( table[index] < max(table[Index]), sumx(filter(Table, [index] > earlier([index]) ) , [Value]) ,table[Index])

 

Sorry, I did not notice that

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

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@Anonymous , if the type or value are incremental in nature try a new column like below. Or add an index column in power query and use that https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

 

 

new column = sumx(filter(Table, [Type] > earlier([Type]) , [Value])

 

or

 

new column = sumx(filter(Table, [Value] > earlier([Value]) , [Value])

 

or

new column = sumx(filter(Table, [index] > earlier([index]) , [Value])

 

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
Anonymous
Not applicable

both the columns are not incremental , column (Type) is a phase & it has to be in sequence . 

@Anonymous , Better to an index column in power query and try, the last formula. I shared a link for index column, if needed

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
Anonymous
Not applicable

Its working now for all scenario's , i've added IF condtion on top your formula:
=
IF (
MAX(Sheet1[Index]) = Sheet1[Index],
Sheet1[TotalCount],
SUMX(FILTER(Sheet1,Sheet1[Index] > EARLIER(Sheet1[Index])),Sheet1[TotalCount]
)
)
 
Anonymous
Not applicable

I did add the index column , its working fine till the 2nd last row , I need to repeat the last row value as is , how I can I do that ? 

 

I used the below formula :

new column = sumx(filter(Table, [index] > earlier([index]) , [Value])

@Anonymous , change like

new column = if( table[index] < max(table[Index]), sumx(filter(Table, [index] > earlier([index]) ) , [Value]) ,table[Index])

 

Sorry, I did not notice that

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
Anonymous
Not applicable

yep its wokring fine , thanks alot .

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.