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
tranguyen
Frequent Visitor

Sum for next row based on condition

 

Hi everyone. I am a fresher in Power BI. Please help to look at 2 pictures below.
- Week wash is a column

- Rank is a column that was created by week wash and month
- Distinctcustomerbycategory is a measure. It will count the number of days of each week except Sunday.

 

With the first picture below. I want to have a condition, If Distinctcustomerbycategory <=2, It will always plus for the next row with Rank = 2. After the value of Distinctcustomerbycategory will return Blank. If It doesn't have any value <= 2. Keep staying all value

 

WhatsApp Image 2024-02-22 at 16.57.20.jpeg  

 

The result I want.
Week wash       Rank               Distinctcustomerbycategory
March 2               1                                       Blank
March 9               2                                          8 (2+6)

March 16             3                                          6 

March 23             4                                          6                                              

March 30             5                                          6

 

 

With the seconde picture below.  If Distinctcustomerbycategory <=2.  It will always plus for the next row with Rank = 1 of next month ( first week of May month). After plus the value of Distinctcustomerbycategory will return Blank. If It doesn't have any value <= 2. Keep stay all value.

 

WhatsApp Image 2024-02-22 at 16.57.20 (1).jpeg

 

Week wash       Rank               Distinctcustomerbycategory
April 6                  1                                          6
April  13               2                                          6

April 20                3                                          5 

April 27                4                                          5                                              

April 30                5                                        Blank
May 5                   1                                         6 (2+4)

Thanks for helping 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @tranguyen ,

 

Try below:

_Value = MAX('Table'[Value]) 

Measure = var _v = [_Value]
var _pre = ADDCOLUMNS('Table',"pre",SUMX(FILTER(ALL('Table'),[Rank]=EARLIER('Table'[Rank])-1),[_Value]))
RETURN IF(_v<=2,"blank",IF(SUMX(_pre,[pre])<=2,_v+SUMX(_pre,[pre]),_v))

vtianyichmsft_0-1708665575252.png

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

6 REPLIES 6
Anonymous
Not applicable

Hi @tranguyen ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1708659376954.png

Measure = var _v = MAX('Table'[Value])
var _pre = ADDCOLUMNS('Table',"pre",SUMX(FILTER(ALL('Table'),[Rank]=EARLIER('Table'[Rank])-1),[Value]))
RETURN IF(_v<=2,"blank",IF(SUMX(_pre,[pre])<=2,_v+SUMX(_pre,[pre]),_v))

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Thanks for helping. But Value in this case is a measure, When I used max([Value]) It showed:
- The MAX function only accepts a column reference as the argument number 1.

Anonymous
Not applicable

Hi @tranguyen ,

 

Try below:

_Value = MAX('Table'[Value]) 

Measure = var _v = [_Value]
var _pre = ADDCOLUMNS('Table',"pre",SUMX(FILTER(ALL('Table'),[Rank]=EARLIER('Table'[Rank])-1),[_Value]))
RETURN IF(_v<=2,"blank",IF(SUMX(_pre,[pre])<=2,_v+SUMX(_pre,[pre]),_v))

vtianyichmsft_0-1708665575252.png

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

@tranguyen , use new table levels calculation , previous should help in this case

 

🚀 Power BI Update: Visual calculations (preview)🚀
https://powerbi.microsoft.com/en-us/blog/visual-calculations-preview/

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

After updating a new Power BI. What should I do now to solve my problems?

Do you have any way to solve this besides updating visual calculations or this is the only way to solve it?

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.