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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Anonymous
Not applicable

Calculated Stock on Hand -at any given point of time

Hi, 

I want to show stock on hand qty at any point of time. 
I have 2 tables 
1.StockBal
2.StockTransaction

 

StockBal table stores  SOH of the item and for a site at the end of every month. So for a item and a for site it will 1 entry per month. StockBal - has Feb data only.


Stock Transaction table stores, daily transactions for a item and site. 


 In order for me to calculated the SOH for Jan. I subtract StockBal Qty with transacted qty to showing historical data. for March I add Stockbal Qty with Transacted qty to get SOH.

StkUnitQty is daily transcated qty


Measure to calculated Culmulated StkUnitQty

Cumulative StkUnitQty =
Var DMnth = ENDOFMONTH(StockTransaction[AccountingDate])
Var HStockdate =ENDOFMONTH(StockBal[StockDate])
Var CQTYafterSTBaldate =

CALCULATE(SUM(StockTransaction[StkUnitQty]),FILTER(StockTransaction
    ,StockTransaction[ItemRef]=EARLIER(StockTransaction[ItemRef])
            && StockTransaction[StorageSite]=EARLIER(StockTransaction[StorageSite])
                && StockTransaction[Unit]=EARLIER(StockTransaction[Unit])
                    &&StockTransaction[AccountingDate]>StockTransaction[DateFTStockBalance]
                        &&StockTransaction[AccountingDate]<=EARLIER(StockTransaction[AccountingDate])))
Var CQTYbeforeSTBaldate =

CALCULATE(SUM(StockTransaction[StkUnitQty]),FILTER(StockTransaction
    ,StockTransaction[ItemRef]=EARLIER(StockTransaction[ItemRef])
            && StockTransaction[StorageSite]=EARLIER(StockTransaction[StorageSite])
                && StockTransaction[Unit]=EARLIER(StockTransaction[Unit])
                    &&StockTransaction[AccountingDate]<=StockTransaction[DateFTStockBalance]
                        &&StockTransaction[AccountingDate]>=EARLIER(StockTransaction[AccountingDate])))

Return IF (StockTransaction[AccountingDate] >StockTransaction[DateFTStockBalance], CQTYafterSTBaldate,CQTYbeforeSTBaldate)



Measure to calculated SOH in Stock Transacted table is 
SOH=

If(StockTransaction[AccountingDate]<=StockTransaction[DateFTStockBalance],
StockTransaction[FTStockBalance]-StockTransaction[Cumulative StkUnitQty]
,IF(StockTransaction[AccountingDate]>StockTransaction[DateFTStockBalance],
StockTransaction[FTStockBalance]+StockTransaction[Cumulative StkUnitQty]))



e.g StockBal for item 14L is 

spandiar_0-1679329359943.png

and Stock Transaction for same is 

spandiar_1-1679329403474.png

When I add this measure then it adds the SOH qty,

spandiar_2-1679329501439.png

Requried result should be 

spandiar_3-1679329796902.png

It should show the next SOH qty rather then same adding the next qty in the previous qty. 

Measure to show final StockHand Qty
Stock on Hand =
CALCULATE(SUM(StockTransaction[SOH])
,FILTER(ALL(Dates),Dates[Date]<=MAX(Dates[Date])))

 




I am sharing the pbix file
https://drive.google.com/file/d/1Z4I3hQgNFCxaIIQJByjkz4S6uj5PmJn8/view?usp=sharing

Thanks.

1 REPLY 1
lbendlin
Super User
Super User

SOH is a caclulated column, not a measure.  it can be simplified:

SOH = If(StockTransaction[AccountingDate]<=StockTransaction[DateFTStockBalance], 
StockTransaction[FTStockBalance]-StockTransaction[Cumulative StkUnitQty]
,StockTransaction[FTStockBalance]+StockTransaction[Cumulative StkUnitQty])

 

Same for Cumulative StkUnitQty - it's a calculated column, not a measure.  And that's probably ok since these values are not influenced by user filters.

 

I have to admit I don't fully understand why you sometimes add and sometimes subtract.  Your calculated columns can be simplified - have a look at the documentation for CALCULATE(), and also consider replacing EARLIER with variables.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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