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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
betty_bui2602
Helper I
Helper I

Calculate inventory at running total

Hello everyone, 

I tried to search for similiar topic in the forum but no solution to solve my issue. I really need some help from expert here. 

I have table with OnHand stock at begining of the month and some in/out transaction monthly 

betty_bui2602_1-1672895529923.png

 

I'd like to calculate stock by at begining of each month consider all transaction

SOH_ = SUMX(FILTER(ALL('Merge_table'),

    'Merge_table'[Item] = EARLIER('Merge_table'[Item]) && 'Merge_table'[Plant] = EARLIER('Merge_table'[Plant]) && 'Merge_table'[Date] <= EARLIER('Merge_table'[Date])),

    'Merge_table'[OnHand] + 'Merge_table'[In Transit] + 'Merge_table'[DistrReceipt (Conf)] + 'Merge_table'[Distr. Receipt (TLB)])

betty_bui2602_2-1672895565293.png

It seems right when with IN. However it mess-up when i include OUT

betty_bui2602_3-1672895668766.png

Whats wrong with my code here? 
TIA 🙂

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@betty_bui2602 , Try have measure like

 

Inventory / OnHand
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),all('Date')) + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

 

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

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

2 REPLIES 2
amitchandak
Super User
Super User

@betty_bui2602 , Try have measure like

 

Inventory / OnHand
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),all('Date')) + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

 

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

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak I watched your vid and tried. But i dont get the result as what you did

betty_bui2602_0-1672899607146.png

SOH_Test return current month only

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.