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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Use previous rows for calculation

dear all,

 

I'm in need of a suggestion for how to calculate a column on base of the comparison of previous rows of other columns.

 

My data set is as follows, what I need to calculate is

 - "(net) Comm Cons": this column should contain the difference when column "Comm.Cons" changes value

 - "Released, Q, H": contains the cummulate sum of "Qty on hand" but, when "Comm.Cons" changes value, the cummulative sum should restart from the current row.

 

any help will be much appreciated

 

Qty on handDateComm. Cons(net) Comm ConsReleased, Q, HQty Expired less consumption
     corrected
110/32/22  11
110/32/22  22
307/31/2023773225
67/31/2023773831
207/31/2023775851
207/31/2023777871
207/31/2023779891
137/31/202377111104
24/30/202581742104
484/30/2025817450104
54/30/2025817455104
484/30/20258174103133
109/30/20251001910133
109/30/20251001920134
1 ACCEPTED SOLUTION

Hi,

This calculated column formula works provided the entries in the "Comm. Cons" column are in ascending order.

(net) Comm. Cons = [Comm. Cons]-CALCULATE(MAX(Data[Comm. Cons]),FILTER(Data,Data[Date]<EARLIER(Data[Date])))

Hope this helps.

Ashish_Mathur_0-1693526172276.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Are you looking for a Power Query solution?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

am looking to a way to calculate in DAX

 

currently, I set those codes:

Comm.Cons(net) = 

CALCULATE(SUM('ShortageReport'[Ordered, Quantity]),
FILTER(ShortageReport, ShortageReport[RM / WIP Item Number] = StockReport[ITEM] && ShortageReport[Start Date] <= 'StockReport'[EXPIRY DATE]),
USERELATIONSHIP(ShortageReport[RM / WIP Item Number], 'StockReport'[ITEM]))
 
Released Q,H = CALCULATE(SUM('StockReport'[QTY ON HAND]), FILTER(StockReport, StockReport[ITEM] = Earlier(StockReport[ITEM]) && StockReport[Index] <= EARLIER(StockReport[Index])))
 
but both are not working as I cannot look into the value of previous row

Hi,

This calculated column formula works provided the entries in the "Comm. Cons" column are in ascending order.

(net) Comm. Cons = [Comm. Cons]-CALCULATE(MAX(Data[Comm. Cons]),FILTER(Data,Data[Date]<EARLIER(Data[Date])))

Hope this helps.

Ashish_Mathur_0-1693526172276.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

thanks. It does work.

I updated to 

StockReport[Cummulative Consumption] - CALCULATE(MAX(StockReport[Cummulative Consumption]), FILTER(StockReportStockReport[ITEM]=earlier(StockReport[ITEM]) && StockReport[EXPIRY DATE]<EARLIER(StockReport[EXPIRY DATE])))

would you have a solution also for the second column, "Released Q,H" so to restart the cumulative sum when "Comm.Cons" changes?

thanks again

You are welcome.  If my previous reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

done, with pleasure

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.