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

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

Reply
heygau
Helper I
Helper I

Need help with DAX

Product Received - Product Sold = Stock Left on Hand (Each  month )

 

If we are left with 1000 stock on hand, that will carry over to the next month

(1000 + Receivals) - Sold = Stock on hand.

 

The opening balance of stock is 27192 as of July 2022. From this point, we need to calculate the stock on hand for each month.We have receivals and sales data for every month from July 2022. Thanks in Advance 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @heygau ,

Thanks for @Musadev  sharing. Please refer to my steps have a try.

Stock on Hand =
VAR OpeningBalance = 27192
VAR CumulativeReceivals =
    CALCULATE (
        SUM ( Receivals[Quantity] ),
        FILTER ( ALL ( 'DateTable' ), 'DateTable'[Date] <= MAX ( 'DateTable'[Date] ) )
    )
VAR CumulativeSales =
    CALCULATE (
        SUM ( Sales[Quantity] ),
        FILTER ( ALL ( 'DateTable' ), 'DateTable'[Date] <= MAX ( 'DateTable'[Date] ) )
    )
RETURN
    OpeningBalance + CumulativeReceivals - CumulativeSales

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @heygau ,

Thanks for @Musadev  sharing. Please refer to my steps have a try.

Stock on Hand =
VAR OpeningBalance = 27192
VAR CumulativeReceivals =
    CALCULATE (
        SUM ( Receivals[Quantity] ),
        FILTER ( ALL ( 'DateTable' ), 'DateTable'[Date] <= MAX ( 'DateTable'[Date] ) )
    )
VAR CumulativeSales =
    CALCULATE (
        SUM ( Sales[Quantity] ),
        FILTER ( ALL ( 'DateTable' ), 'DateTable'[Date] <= MAX ( 'DateTable'[Date] ) )
    )
RETURN
    OpeningBalance + CumulativeReceivals - CumulativeSales

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

heygau
Helper I
Helper I

Thanks @Musadev 

heygau_1-1709601914381.png

 

 

 

I want to calculate
Stock on hand =  [(Opening Balance + Bales Received) - Bales Sold]
I have to consider the opening balance from June 2023 and should continue with the result value on the Stock on hand column. 



Bales Received is a measure = SUM(Bales Received ) and Bales Sold as well, from multiple tables. Thanks.

Hi @heygau 
Can you please share the sample data in the Insert statement of Oracle DB? 

Musadev
Resolver III
Resolver III

Hi @heygau 
You will need to create 4 measures.
Product Received,
Product Sold,
Stock on hand,
Stock Left CM (Current Month)
Stock Left PM (Previous Month)

The last 2 will be the same for consecutive dates. 

If you can share the insert statement of the sample data to oracle Database, i will share the measures script as well. 

 

Helpful resources

Announcements
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