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
rajasekar_o
Helper V
Helper V

how to calculate daily inventory Opening quantity and closing quantity

i have the data of inventory 

DateItempluseorminesQty
31-03-2017RM ITEM Ap125000
01-04-2022RM ITEM Ap1000
02-04-2022RM ITEM Ap333
02-08-2022RM ITEM Ap200
02-02-2023RM ITEM Am100
02-02-2023RM ITEM Ap100
11-03-2023RM ITEM Ap100
31-03-2023RM ITEM Ap1100
04-04-2023RM ITEM Ap167
10-04-2023RM ITEM Am1
10-04-2023RM ITEM Ap80
13-04-2023RM ITEM Am1
13-04-2023RM ITEM Ap39
04-05-2023RM ITEM Ap50
05-05-2023RM ITEM Am1
20-05-2023RM ITEM Ap55
30-05-2023RM ITEM Ap10
04-07-2023RM ITEM Am10
05-09-2023RM ITEM Ap210
06-09-2023RM ITEM Am160
06-09-2023RM ITEM Ap355
09-09-2023RM ITEM Am10
09-09-2023RM ITEM Ap10
15-09-2023RM ITEM Ap160
16-09-2023RM ITEM Ap135
19-09-2023RM ITEM Ap28
20-09-2023RM ITEM Ap10
02-10-2023RM ITEM Ap33

 

I try but not correct

 

rajasekar_o_0-1707995166902.png

i try this its not working 

Onhand Opening = CALCULATE(SUM(STOCKVALUE[IN Qty]),filter(all(Calender),Calender[Date] <min(Calender[Date]))) -
CALCULATE(SUM(STOCKVALUE[Out Qty]),filter(all(Calender),Calender[Date] <min(Calender[Date])))
 
onhand closing = CALCULATE(SUM(STOCKVALUE[QTY]),filter(all(Calender),Calender[Date] <=Max(Calender[Date]))) -
CALCULATE(SUM(STOCKVALUE[Out Qty]),filter(all(Calender),Calender[Date] <= Max(Calender[Date])))


how to calculate inventory opening Qty and Closing Qty

1 ACCEPTED SOLUTION

@rajasekar_o , You have to add filter of P and M

 

Onhand Opening = CALCULATE(SUM(STOCKVALUE[IN Qty]),filter(all(Calender),Calender[Date] <min(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")

) -
CALCULATE(SUM(STOCKVALUE[Out Qty]),filter(all(Calender),Calender[Date] <min(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "M")

)

onhand closing = CALCULATE(SUM(STOCKVALUE[QTY]),filter(all(Calender),Calender[Date] <=Max(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")

) -
CALCULATE(SUM(STOCKVALUE[Out Qty]),filter(all(Calender),Calender[Date] <= Max(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")

)

 

 

Using window function without Date

 

CLosing = CALCULATE(CALCULATE(SUM(STOCKVALUE[Qty]),FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")) ,WINDOW(0,ABS,0,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date]))) - CALCULATE(SUM(STOCKVALUE[Qty]), WINDOW(0,ABS,0,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date])), FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "M"))
 
 
Opening = CALCULATE(CALCULATE(SUM(STOCKVALUE[Qty]),FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")) ,WINDOW(0,ABS,-1,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date]))) - CALCULATE(SUM(STOCKVALUE[Qty]), WINDOW(0,ABS,-1,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date])), FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "M"))
 
 
The date table is better, as you do not have to worry about other columns like pluseormines in Visual
 
File attached
 
 
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

3 REPLIES 3
amitchandak
Super User
Super User

@rajasekar_o , With help from a data table

 

Onhand Opening= CALCULATE(SUM(Table[In]),filter(all(date),date[date] <min(date[date]))) -
CALCULATE(SUM(Table[Out]),filter(all(date),date[date] <min(date[date])))


onhand closing= CALCULATE(SUM(Table[In]),filter(all(date),date[date] <=Max(date[date]))) -
CALCULATE(SUM(Table[Out]),filter(all(date),date[date] <= Max(date[date])))

 

Power BI Inventory On Hand: https://youtu.be/nKbJ9Cpb-Aw

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

its not working 

rajasekar_o_0-1708011044202.png

 

@rajasekar_o , You have to add filter of P and M

 

Onhand Opening = CALCULATE(SUM(STOCKVALUE[IN Qty]),filter(all(Calender),Calender[Date] <min(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")

) -
CALCULATE(SUM(STOCKVALUE[Out Qty]),filter(all(Calender),Calender[Date] <min(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "M")

)

onhand closing = CALCULATE(SUM(STOCKVALUE[QTY]),filter(all(Calender),Calender[Date] <=Max(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")

) -
CALCULATE(SUM(STOCKVALUE[Out Qty]),filter(all(Calender),Calender[Date] <= Max(Calender[Date]))

,FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")

)

 

 

Using window function without Date

 

CLosing = CALCULATE(CALCULATE(SUM(STOCKVALUE[Qty]),FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")) ,WINDOW(0,ABS,0,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date]))) - CALCULATE(SUM(STOCKVALUE[Qty]), WINDOW(0,ABS,0,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date])), FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "M"))
 
 
Opening = CALCULATE(CALCULATE(SUM(STOCKVALUE[Qty]),FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "P")) ,WINDOW(0,ABS,-1,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date]))) - CALCULATE(SUM(STOCKVALUE[Qty]), WINDOW(0,ABS,-1,REL, ALL(STOCKVALUE[Item], STOCKVALUE[Date]), ORDERBY([Date])), FILTER(STOCKVALUE,STOCKVALUE[pluseormines]= "M"))
 
 
The date table is better, as you do not have to worry about other columns like pluseormines in Visual
 
File attached
 
 
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

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.