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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JKO75
Frequent Visitor

Cummulative stocklevel backwards

Hello,

I have

a table showing the current stock levels of today

a table showing the transaction done in the past, Ingoing and Outgoing where outgoing has a negative value and incoming a positive value. 

a date table

Stock  
ProductStock LevelStock Value
A10010000
B15012000
C756000
D304000

 

Transactions    
DateTypeProductQuantityValue
26-7-2023OutA-5500
26-7-2023OutB-10800
25-7-2023INC252100
25-7-2023INA101000
25-7-2023OutD-101350
24-7-2023OutD-101350
24-7-2023OutA-101000
24-7-2023OutB-201600
24-7-2023INB504200
24-7-2023IND101250
24-7-2023OutC-10800

 

What I would like to have is the stock level and stock value for the each date. Any suggestions? 

Many thanks for your help

3 REPLIES 3
Anonymous
Not applicable

HI @JKO75,

You can add a variable to lookup the stock table based on the current product to get the initiation value.
Then you can write a cumulative calculation formula based on product and calculate with the initiation value of show the rolling results.

formula =
VAR currDate =
    MAX ( Transactions[Date] )
VAR currProduct =
    SELECTEDVALUE ( Transactions[Product] )
VAR init =
    LOOKUPVALUE ( Stock[Stock Value], Stock[Product], currProduct )
VAR rolling =
    CALCULATE (
        SUM ( Transactions[Value] ),
        FILTER ( ALLSELECTED ( Transactions ), [Date] <= currDate ),
        VALUES ( Transactions[Product] )
    )
RETURN
    init + rolling

Regards,

Xiaoxin Sheng

Hello Sheng, Thank you. 

When using this I get the initial Stock value minus the total transaction done in the past. What I'm looking for is the Stocklevel for each day in the past. eg

Stocklevel Yesterday = Stocklevel - Transactions Yesterday and

Stocklevel day before Yesterday = Stocklevel Yesterday - Transaction day before yesterday. etc 

Anonymous
Not applicable

Hi @JKO75,

Sure, you can duplicate the rolling variable and remove the '=' operator to get the rolling result to previous. Then you can calculate with initialize stock with current rolling - previous rolling to get the daily stock:

formula =
VAR currDate =
    MAX ( Transactions[Date] )
VAR currProduct =
    SELECTEDVALUE ( Transactions[Product] )
VAR init =
    LOOKUPVALUE ( Stock[Stock Value], Stock[Product], currProduct )
VAR rolling =
    CALCULATE (
        SUM ( Transactions[Value] ),
        FILTER ( ALLSELECTED ( Transactions ), [Date] < currDate ),
        VALUES ( Transactions[Product] )
    )
VAR rollingtoDate =
    CALCULATE (
        SUM ( Transactions[Value] ),
        FILTER ( ALLSELECTED ( Transactions ), [Date] <= currDate ),
        VALUES ( Transactions[Product] )
    )
RETURN
    init + ( rollingtoDate - rolling )

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.