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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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