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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Dor-Y13
Frequent Visitor

Creating a Aggregated Inventory measure

Hello,

i am trying to create a report for my inventory movements, i would like to know the exact balance of inventory for each date that has Inventory move.

please see table below for clarification purposes (i am computing a PBI report off course):

DorY13_0-1715601323105.png

 

the desired measure is the Yellow one, which shows the inventory balance after the movements of the same row (with respect to the remaining balance before this date).

Could you please help me with the desired DAX function and what i am missing?

Thanks a lot in advance

 

2 ACCEPTED SOLUTIONS
hackcrr
Memorable Member
Memorable Member

Hi, @Dor-Y13 

Based on the data provided in your image and the expected results of the yellow column metrics, I used the following SAMPLE example data:

hackcrr_0-1715603853304.png

I created a metric using the following DAX expression:

Stock aggregated balance = 
VAR _table =
    CALCULATETABLE (
        SUMMARIZE (
            'Table2',
            'Table2'[Base date],
            'Table2'[Stock In],
            'Table2'[Stock out],
            "_rolling1",
                VAR _total =
                    CALCULATE (
                        SUM ( Table2[Stock In] ),
                        FILTER (
                            ALL ( 'Table2' ),
                            'Table2'[Base date] <= EARLIER ( Table2[Base date] )
                        )
                    )
                RETURN
                    _total,
            "_rolling2",
                VAR _total =
                    CALCULATE (
                        SUM ( Table2[Stock out] ),
                        FILTER ( ALL ( Table2 ), 'Table2'[Base date] <= EARLIER ( Table2[Base date] ) )
                    )
                RETURN
                    _total
        )
    )
VAR _rollingTotal_stock_In =
    MAXX (
        FILTER ( _table, 'Table2'[Base date] = SELECTEDVALUE ( Table2[Base date] ) ),
        [_rolling1]
    )
VAR _rollingTotal_stock_Out =
    MAXX (
        FILTER ( _table, 'Table2'[Base date] = SELECTEDVALUE ( Table2[Base date] ) ),
        [_rolling2]
    )
RETURN
    _rollingTotal_stock_In - _rollingTotal_stock_Out

Using this metric in table gives you the expected result of your scalar yellow:

hackcrr_1-1715603958778.png

 

 

Best Regards,

hackcrr

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

Anonymous
Not applicable

Hi @Dor-Y13 

 

Thanks for the reply from @hackcrr , please allow me to provide another insight:

Here I create a measure, it's easily to understand that the outcome is the result of the cumulative values of Stock In minus Stock Out:

MEASURE =
VAR _currentDate =
    MAX ( 'Table'[Base date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Stock In] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Base date] <= _currentDate )
    )
        - CALCULATE (
            SUM ( 'Table'[Stock Out] ),
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Base date] <= _currentDate )
        )

 The result is as follow:

vzhengdxumsft_1-1715664019074.png

Best Regards

Zhengdong Xu
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

3 REPLIES 3
Anonymous
Not applicable

Hi @Dor-Y13 

 

Thanks for the reply from @hackcrr , please allow me to provide another insight:

Here I create a measure, it's easily to understand that the outcome is the result of the cumulative values of Stock In minus Stock Out:

MEASURE =
VAR _currentDate =
    MAX ( 'Table'[Base date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Stock In] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Base date] <= _currentDate )
    )
        - CALCULATE (
            SUM ( 'Table'[Stock Out] ),
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Base date] <= _currentDate )
        )

 The result is as follow:

vzhengdxumsft_1-1715664019074.png

Best Regards

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

Hello, sorry for the so late respone. 

I did like the simple version of this DAX, however it does not get me to the end result needed (I get really high figures on the new Measure, these numbers are not realistic so there is some kind of a problem in the calculation).

 

Could you might help me how to figure out where the high numbers come from? i am working on an ERP that i cannot upload a file for reference, however i will be happy to solve that issue.

 

Thanks a lot

hackcrr
Memorable Member
Memorable Member

Hi, @Dor-Y13 

Based on the data provided in your image and the expected results of the yellow column metrics, I used the following SAMPLE example data:

hackcrr_0-1715603853304.png

I created a metric using the following DAX expression:

Stock aggregated balance = 
VAR _table =
    CALCULATETABLE (
        SUMMARIZE (
            'Table2',
            'Table2'[Base date],
            'Table2'[Stock In],
            'Table2'[Stock out],
            "_rolling1",
                VAR _total =
                    CALCULATE (
                        SUM ( Table2[Stock In] ),
                        FILTER (
                            ALL ( 'Table2' ),
                            'Table2'[Base date] <= EARLIER ( Table2[Base date] )
                        )
                    )
                RETURN
                    _total,
            "_rolling2",
                VAR _total =
                    CALCULATE (
                        SUM ( Table2[Stock out] ),
                        FILTER ( ALL ( Table2 ), 'Table2'[Base date] <= EARLIER ( Table2[Base date] ) )
                    )
                RETURN
                    _total
        )
    )
VAR _rollingTotal_stock_In =
    MAXX (
        FILTER ( _table, 'Table2'[Base date] = SELECTEDVALUE ( Table2[Base date] ) ),
        [_rolling1]
    )
VAR _rollingTotal_stock_Out =
    MAXX (
        FILTER ( _table, 'Table2'[Base date] = SELECTEDVALUE ( Table2[Base date] ) ),
        [_rolling2]
    )
RETURN
    _rollingTotal_stock_In - _rollingTotal_stock_Out

Using this metric in table gives you the expected result of your scalar yellow:

hackcrr_1-1715603958778.png

 

 

Best Regards,

hackcrr

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

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors