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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
DineshJadhav
Regular Visitor

Inventory and Stock balance calculation

I have three tables Invenotry,Supply and Demand by SKUs
https://docs.google.com/spreadsheets/d/1a4tus4q_D2BjoVrkTvgMSytNinJUG0CB/edit?usp=drive_link&ouid=10... 
1.Inventory table is for  Current month i.e. Feb/2026

2.Demand Table by SKU and month
3. Supply Table by SKU and Month
 
I want to calculate stock balance for Each month

Stock balance Feb/2026 = Inventory Feb/2026 + Supply Feb/2026 - Feb/2026 Demand

And Stock balance of Previous month should be Inventory for Next month

i.e Stock Balance Mar/2026 = Stock balance Feb/2026  + Supply Mar/2026 - Mar/2026 Demand

For Stock balance I am using below Dax
 
Stock Balance by SKU (EA) =
VAR CurrentMonthKey =
    SELECTEDVALUE ( 'Month Table'[Month Key] )

VAR StartMonthKey =
    CALCULATE (
        MIN ( 'Month Table'[Month Key] ),
        ALLSELECTED ( 'Month Table' )
    )

RETURN
SUMX (
    VALUES ( 'Masterial Master SKUs'[Material] ),

    VAR OpeningAtStart_forSKU =
        CALCULATE (
            SUM ( 'Inventory On Hand(EA)'[IOH Qty (EA)] ),
            'Month Table'[Month Key] = StartMonthKey
        )

    VAR NetFlow_Start_to_Current_forSKU =
        CALCULATE (
            SUM ( Supply[Supply Qty (EA)] ) - SUM ( Demand[Demand Qty (EA)] ),
            -- intersect (do not overwrite) existing filters
            KEEPFILTERS (
                'Month Table'[Month Key] >= StartMonthKey
                    && 'Month Table'[Month Key] <= CurrentMonthKey
            )
        )

    RETURN
        COALESCE ( OpeningAtStart_forSKU, 0 )
        + COALESCE ( NetFlow_Start_to_Current_forSKU, 0 )
)
But it is calulating Stock balance for Mar/2026 consdering Feb/2026 Inventory rather tahn Feb2026 stock balance
Could you please provide me correct DAX? 
2 ACCEPTED SOLUTIONS

Hi @DineshJadhav ,

Thank you for following up.
I’ve attached the PBIX file, which contains the full working setup, including the sample data model, relationships, base measures, and the final running stock balance calculation.

This approach anchors the calculation to the opening inventory of the first visible month and then accumulates the net movement (Supply minus Demand) up to the current month. By adding this cumulative movement to the opening inventory, the balance rolls forward correctly each month without referencing the previous month’s result directly.

Please find the attached .pbix file below.


View solution in original post

Hi @DineshJadhav please try this

 

Stock Balance by SKU =
VAR CurrentMonth =
    MAX ( 'Date Table'[Month Index] )

VAR FirstMonth =
    CALCULATE (
        MIN ( 'Date Table'[Month Index] ),
        ALLSELECTED ( 'Date Table'[Month Index] )
    )

RETURN
SUMX (
    VALUES ( SKU[SKU Code] ),

    VAR OpeningInventory =
        CALCULATE (
            SUM ( Inv[Inventory On Hand] ),
            'Date Table'[Month Index] = FirstMonth
        )

   VAR MovementToDate =
    CALCULATE (
        [Net Movement],
        FILTER (
            ALL ( 'Date Table'[Month Index] ),
            'Date Table'[Month Index] >= FirstMonth
                && 'Date Table'[Month Index] <= CurrentMonth
        )
    )

    RETURN
        OpeningInventory + MovementToDate
)
 
 
Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

View solution in original post

15 REPLIES 15
techies
Super User
Super User

Hi @DineshJadhav i tried accessing the google sheet, its not opening on my end.

 

 

Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

Hi @techies .Could you please check it now.. You will be able to access it now. 
else you can use below link
https://docs.google.com/spreadsheets/d/1a4tus4q_D2BjoVrkTvgMSytNinJUG0CB/edit?usp=sharing&ouid=10094...

Yes, i can access now, thank you.

 

Will review and get back shortly.

 

 

Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

Hi @DineshJadhav please try this

 

Stock Balance by SKU =
VAR CurrentMonth =
    MAX ( 'Date Table'[Month Index] )

VAR FirstMonth =
    CALCULATE (
        MIN ( 'Date Table'[Month Index] ),
        ALLSELECTED ( 'Date Table'[Month Index] )
    )

RETURN
SUMX (
    VALUES ( SKU[SKU Code] ),

    VAR OpeningInventory =
        CALCULATE (
            SUM ( Inv[Inventory On Hand] ),
            'Date Table'[Month Index] = FirstMonth
        )

   VAR MovementToDate =
    CALCULATE (
        [Net Movement],
        FILTER (
            ALL ( 'Date Table'[Month Index] ),
            'Date Table'[Month Index] >= FirstMonth
                && 'Date Table'[Month Index] <= CurrentMonth
        )
    )

    RETURN
        OpeningInventory + MovementToDate
)
 
 
Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

Hi @techies 
Thank you for you response. 
I am still facing the same issue Stock balance is still not carrying forward to next month as opening inventory.
Could you please share the file so that I can check how you applied this logic?

Hi @DineshJadhav please review and let me know.

 

 

Power BI & Microsoft Fabric
PL-300 | DP-600 | DP-700 Certified

DineshJadhav_0-1773839287132.png

Hi @techies ,
Thank you for the file
Currently DAX is calculating correct stock balance only for first month. but for Mar 2026 Stock balance should be 
Stock balance from Feb 2026 + Supply Mar 2026 - Demand Mar 2026
4,925,741+598,916-527,775 = 4,996,882 currently it is just showing Net movement as stock balance for Mar 2026. It is not considering as last months stock balance and carry it forward to next month

DineshJadhav
Regular Visitor

Hi @v-sshirivolu,
Thank you for the input.It will be really helpfull if can suggest correct DAX

Hi @DineshJadhav ,

Thank you for following up.
I’ve attached the PBIX file, which contains the full working setup, including the sample data model, relationships, base measures, and the final running stock balance calculation.

This approach anchors the calculation to the opening inventory of the first visible month and then accumulates the net movement (Supply minus Demand) up to the current month. By adding this cumulative movement to the opening inventory, the balance rolls forward correctly each month without referencing the previous month’s result directly.

Please find the attached .pbix file below.


HI @DineshJadhav ,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions 

Hi @DineshJadhav ,

I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you

 

Hi @v-sshirivolu,
This is working for Me. Sorry I forget to reply on this. 

Thank you. Really Appreciate your help.

Hi @DineshJadhav ,

Glad to hear it’s working for you. Thanks for the update.
Feel free to reach out if you need any further help.

Best regards,
v-sshirivolu

Hi @DineshJadhav,

to provide the correct DAX we need more information.

 

DAX has different results based on the context, so we need to know the context in which your calculation is performed. Please provide a clear set of images showing which columns are grouped in the visual where you are using the measure, and any slicer interacting, a picture fo the data model and a short description on each image, so we can get the necessary insights.

 

Thank you.

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

v-sshirivolu
Community Support
Community Support

Hi @DineshJadhav ,
The current calculation approach anchors the logic to the first month’s inventory, which prevents the balance from accumulating month by month. Instead, you need a running calculation that begins with the opening inventory of the first visible month (such as February 2026) and then adds supply and subtracts demand for each subsequent month. For example, February’s balance should be calculated as Inventory plus Supply minus Demand for that month. March’s calculation should use February’s ending balance, add March supply, and subtract March demand. In DAX, this can be achieved by fixing the opening inventory at the first visible month and calculating a cumulative total of (Supply minus Demand) from that month up to the current month. By adding the opening inventory to this cumulative net movement, the measure will correctly carry forward the balance for each month without manually referencing the previous month’s result.

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.