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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
VKB
Frequent Visitor

DAX for computation of Opening and Closing Balance of Inventory

Hello Experts,
Need help in fixing the DAX queries to compute Opening and Closing Balance and suggestions to improve other DAXmeasures.

 

While I was trying to make 2 tables (One on Monthly and the other on Daily status) on inventory movements, there are issues with the Opening and Closing Balances calculation.  link to the .pbix file has been given below. The objective is to show the stock quantity in the format of 'Item name' as rows and  |Opening Balance| Purchases | Production | Sales | Closing Balance| as columns. on the top of these columns, I need 'Months' in one table and 'Dates' in the other (The below pics are for your reference):

VKB_0-1670496608911.pngVKB_1-1670496629550.png

 

https://drive.google.com/file/d/1W2nO7Fd6JmQmgGg4Q5P2w0TdVjDWXm44/view?usp=share_link

Kindly refer to all other measures too and guide me wherever improvements can be done. 

 

Cheers!

Venkat

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @VKB ,

Modified the formula.

vcgaomsft_2-1670824485796.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

4 REPLIES 4
VKB
Frequent Visitor

@Anonymous Thank you for your kind responce. While  checking the output, The source data, Jan-22 does'nt have any Opening Balance and Feb-22 Opening balance shall be equal to Jan-22's Closing Balnace and likewise, the DAX should print the numbers for all months with similar logic.  hope this requirement make sense.

 

Cheers,
Venkat!

Anonymous
Not applicable

Hi @VKB ,

Modified the formula.

vcgaomsft_2-1670824485796.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

VKB
Frequent Visitor

It's working,
Thank you!

Anonymous
Not applicable

Hi @VKB ,

Please try:

Opening Stock 2 = 
VAR _mindate = FIRSTDATE( 'Stock Register'[Date] )
VAR _result = 
CALCULATE(
    SUM( 'Stock Register'[Quantity] ),
    'Date'[Date] <= _mindate
)
RETURN
_result
Closing Stock 2 = 
VAR _maxdate = LASTDATE( 'Stock Register'[Date] )
VAR _result = 
CALCULATE(
    SUM( 'Stock Register'[Quantity] ),
    'Date'[Date] <= _maxdate
)
RETURN
_result

vcgaomsft_0-1670572047971.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors