Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Stock On Hand Measure From Stock-In Table and Sales Table

I need to create a measure that caulculates the stock on hand at any given day for an item based on a sales table:

 

ITEMSALE_AMOUNTSALE_DATE
A10002022-05-23
B5002022-05-23
C20002022-05-22
A30002022-05-22
C2002022-05-21
A1002022-05-20

 

And a Stock-In table:

ITEMQUANTITYSTOCKED_DATE
A50002022-05-19
B45002022-05-19
C50002022-05-19
A5000 2022-05-22

 

I would like to be able to plot stock on hand against date and filter by ITEM.

 

I have looked at other posts and tried various methods including creating a date table but can't seem to get it right.

 

Appreciate any help.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi

     

    Try This

    Stock situation =
    VAR stockdatevalue =
    SELECTEDVALUE ( 'Date'[Date] )
    VAR stockqty =
    CALCULATE (
    SUM ( Stock[Stock] ),
    ALL ( 'Date'[Date] ),
    Stock[Date] <= stockdatevalue
    )
    VAR salesqty =
    CALCULATE (
    SUM ( 'Stock SALES'[sales] ),
    ALL ( 'Date'[Date] ),
    'Stock SALES'[Date] <= stockdatevalue
    )
    RETURN
    stockqty - salesqty

  • Anonymous , what would stock on 20th May. blank or 14500. Create a date table join with both the tables on date

     

    For stock try a meausre like

     

    calculate(lastnonblank(Date[Date], sum(Stock[Quanity]), filter(all(date), Date[date]<= max(Date[date])))

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the help amitchandak, ideally the stock on 20th May would be 14400 (total stock less 100 of item A sold). I will try your suggestions later today.