Forum Discussion

JR_Lee's avatar
JR_Lee
Frequent Visitor
4 years ago
Solved

Calculating cumulative stock value

StockValue = CALCULATE(
                SUM ('Ledger Entry'[Quantity] * 'Ledger Entry'[Current Value] )
                FILTER (ALL(Date), Date[Date] <= MAX('Date'[Date])))

Hi,

 

I have a data set where I need to calculate the warehouse cumulative stock levels and the valuation of this stock.

 

I started by creating a date table and making a relationship between the data table and the picking date.

 

I then created a DAX formula to calculate cumulative stock levels (which works):

Cumulative Total =
CALCULATE (
    SUM ( 'Ledger Entry'[Quantity] ),
    FILTER ( ALL ( 'Date'[Date] ), ( 'Date'[Date] ) <= MAX ( 'Date'[Date] ) )
)

 

Then I made a relationship between the item SKU's

And then created a calculated column on the Ledger Entry table to obtain the current value:

Current Value =
LOOKUPVALUE ( 'Item'[Standard Cost], 'Item'[No_], 'Ledger Entry'[Item No_] )

 

I'm not understanding exactly what I'm doing at this point as I found the solution on Google.

I use the following DAX to try and calculate the cumulative stock value but it's giving me syntax errors (not really sure if this solution would even be correct).

  • JR_Lee  and if you don't want to create dimension tables

     

    cumulativeQuantity =
    CALCULATE (
        SUM ( t2[Quantity] ),
        FILTER ( ALL ( t2 ), t2[Posting Date] <= MAX ( t2[Posting Date] ) )
    )
    
    
    _Cumulative Stock Value = 
    CALCULATE (
        SUMX ( t1, t1[Standard Cost] * related(t2[Quantity]) ),
        FILTER ( ALL ( t2), t2[Posting Date] <= MAX ( t2[Posting Date] ) )
    )

     

     

13 Replies

  • JR_Lee's avatar
    JR_Lee
    Frequent Visitor

    Oops, the DAX at the top should be at the very bottom.

    • smpa01's avatar
      smpa01
      Icon for Community Champion rankCommunity Champion

      JR_Lee  any chance you can provide sample data and desired output?

      • JR_Lee's avatar
        JR_Lee
        Frequent Visitor

        My data consists of the below (plus the added calculated column, and my date table)

        Item Table:

        No_Standard Cost
        00210833.04
        002108SH36.52
        01211736237.91
        01211736337.91
        01211736427.48
        01211736550.43
        01211736619.13
        01211736724
        01211736811.48
        012117369

        5.9


        Ledger Entry table:

        Item No_Posting DateQuantity
        0021082/10/2021158
        002108SH2/10/2021-248
        0121173622/10/2021-3
        0121173632/10/202172
        012117364

        3/10/2021

        311
        0121173653/10/202176
        0121173663/10/202154
        0121173674/10/2021-10
        0121173684/10/20213
        0121173694/10/202129

         

        Expected result should be like:


        I can get the cumulative quantity working just not the calculation of the stock value.
        Thanks.

  • Anonymous's avatar
    Anonymous
    Not applicable

    smpa01 Hi SuperUser

    I dont have any blank value in my Cumulative measure yet the first value is not picked. Any reason why