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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JR_Lee
Frequent Visitor

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.

 

JR_Lee_0-1636019158179.png

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

JR_Lee_1-1636019286298.png

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).

1 ACCEPTED SOLUTION

@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] ) )
)

 

smpa01_0-1636117866745.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

13 REPLIES 13
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

Cumulative PowerBI.JPG

JR_Lee
Frequent Visitor

Thanks @smpa01, that's really helpful.

JR_Lee
Frequent Visitor

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

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

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
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:

JR_Lee_0-1636036640620.png


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

@JR_Lee  what is the expected output based on the sample data that you provided?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
JR_Lee
Frequent Visitor

Hi @smpa01 
Not too sure exactly as I just typed up the data in my reply as a loose example and my table has 8m rows.
The expected output should be the cumulative result of standard cost x current value of standard cost - I think?
Sorry if this is not clear.

@JR_Lee  can you take a moment to take a look into what you provided and what it should yield to?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
JR_Lee
Frequent Visitor

DateCumulative QtyCumulative Stock Value
02/10/2021-46-£1,220.85
03/10/2021441£12,191.13
04/10/202122£12,156.67

 

Hi, so this should be the result of the data I provided above. Does this help?

@JR_Lee  and how did you reach to this number? Can you describe the logic?

 

I only tested Cumulative Qty and it does not make sense to me how you reached at -46 for 2021-10-02 while sum of all the quantity for that amounts to -21?

 

Please clearly describe how did you reach to each of those numbers for each of the day for both Cumulative Qty and Cumulative Stock Value

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
JR_Lee
Frequent Visitor

Sorry, I realised I was summing Qty individually rather than cumulatively.
The below should be correct - the stock value should also be correct.

 

-21
420
442

@JR_Lee  pbix is attached

 

smpa01_0-1636117204391.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@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] ) )
)

 

smpa01_0-1636117866745.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.