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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Recursive calculation issue using previous_value

Hi,

I am trying to migrate one of my dashboard from Tableau to PowerBI. I need to calculate Cumulative backlog in such a way that Cumulative backlog is sum of daily backlog column and can not go negative. I achieved it using following formula in Tableau.

 

IF (PREVIOUS_VALUE(SUM([Daily Backlog])) + SUM([Daily Backlog])) <0
then 0 ELSE
(PREVIOUS_VALUE(SUM([Daily Backlog])) + SUM([Daily Backlog]))
END

 

I am sharing an example table showing the expected outcome for "Cumulative Backlog" column below. 

Since PREVIOUS_VALUE function doesn't exist in PowerBI, how can i achieve the same result. I tried many options but PowerBI shows a loop error. Please help.

 

DateDaily BacklogCumulative Backlog
1-Mar8181
2-Mar-5031
3-Mar-400
4-Mar33
5-Mar3033
6-Mar2558
7-Mar-600
8-Mar-140
9-Mar-250
10-Mar22
11-Mar7476
12-Mar53129
13-Mar-11118
14-Mar-4276
15-Mar31107
16-Mar-8225
17-Mar3863
1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Inset an Index column with 1 start and use below formula in a custom column

 

= List.Accumulate(List.FirstN(#"Added Index"[Daily Backlog],[Index]),0,(s,c)=> List.Max({0,s+c}))

 

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Pc7BDcAgCIXhXThrIhWUDtEJjIeu0P0PTYDn8Qug/1rE9Xk/KmRMuyy6klWbu8MSlnR3KRTDkbzUOXE7Ymwwi/uGc58b7oNIm7HOaNP4nE8bRzvLic0XTl8uILBaLiCxG+39Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Daily Backlog" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Daily Backlog", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Bufferd List" = List.Buffer(#"Added Index"[Daily Backlog]),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Cumulative Backlog", each List.Accumulate(List.FirstN(#"Bufferd List",[Index]),0,(s,c)=> List.Max({0,s+c}))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Inset an Index column with 1 start and use below formula in a custom column

 

= List.Accumulate(List.FirstN(#"Added Index"[Daily Backlog],[Index]),0,(s,c)=> List.Max({0,s+c}))

 

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Pc7BDcAgCIXhXThrIhWUDtEJjIeu0P0PTYDn8Qug/1rE9Xk/KmRMuyy6klWbu8MSlnR3KRTDkbzUOXE7Ymwwi/uGc58b7oNIm7HOaNP4nE8bRzvLic0XTl8uILBaLiCxG+39Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Daily Backlog" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Daily Backlog", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Bufferd List" = List.Buffer(#"Added Index"[Daily Backlog]),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Cumulative Backlog", each List.Accumulate(List.FirstN(#"Bufferd List",[Index]),0,(s,c)=> List.Max({0,s+c}))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

 

Anonymous
Not applicable

Thanks Vijay_A_Verma for sharing the solution.

 

I am doing this calculation using parameters on the frontend rather than in the backend. 

Hence, solution you provided using powerquery is not going to work. Can you suggest an alternate way of achieving it using DAX?

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors