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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
svandamme
Frequent Visitor

Stock Movements Calculation

Hi,

 

I have a stock movements table that contains stock movements for the dates there is a stock movement, so not all the dates are in the table. I want to create a report that shows for every date the stock at that moment. So if there is a stock movement on jan 1 and jan 3, I want to be able to see the stock on jan 2 also.

I have already created a formula and it works on row level but on Grand Total level it is wrong.

 

The formula is the following one:

Qty:=SUMX (
VALUES ( ‘ITEM_VARIANT'[PK_Item_Variant] ),
CALCULATE (
SUM (F_STOCK_MOVEMENTS[M_Stock_Running_Qty] ),
CALCULATETABLE (
LASTNONBLANK (
‘DATE'[Calendar_Date],
CALCULATE ( COUNTROWS ( F_STOCK_MOVEMENTS ) )
),
DATESBETWEEN (
‘DATE'[Calendar_Date],
BLANK (),
MAX ( ‘DATE'[Calendar_Date] )
))))

 

I have solved this another way by creating in SQL a table but then I go from 10M rows to 750M rows. It works and it is performant but I would prefer to solve it with a measure. I think I am close but I just cannot figure out how to get the grand total correct.

I have put the file on Google Drive:

https://drive.google.com/open?id=1a8xEsxL_Llh_rSOkEWcbnKdMda76qSX7

 

If someone has any suggestions, please let me know. 

 

Thanks in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @svandamme,

 

Maybe you can try to use below formula:

Measure = 
var temp=CALCULATE (
    SUM ( F_STOCK_MOVEMENTS[M_Stock_Movement_Qty] ),
    FILTER (
        ALLSELECTED ( F_STOCK_MOVEMENTS ),
        [FK_Date] <= MAX ( F_STOCK_MOVEMENTS[FK_Date])
    ),
    VALUES ( F_STOCK_MOVEMENTS[BK_Item_Code] ),
    VALUES ( F_STOCK_MOVEMENTS[BK_Location_Code] )
)
return
if(temp= BLANK(),[Stock],temp)

My formula can't replace previous blank records, so I use 'stock' measure to replace blank part.

 

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @svandamme,

 

Please share original table data for test and coding format. Current power bi is not suitable to analytics pivoted excel workbook sheet.

 

According to your description, it seems like normal running total calculation, you can refer to below link to know more about these.

Running Total Techniques in DAX

 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi @svandamme,

 

Maybe you can try to use below formula:

Measure = 
var temp=CALCULATE (
    SUM ( F_STOCK_MOVEMENTS[M_Stock_Movement_Qty] ),
    FILTER (
        ALLSELECTED ( F_STOCK_MOVEMENTS ),
        [FK_Date] <= MAX ( F_STOCK_MOVEMENTS[FK_Date])
    ),
    VALUES ( F_STOCK_MOVEMENTS[BK_Item_Code] ),
    VALUES ( F_STOCK_MOVEMENTS[BK_Location_Code] )
)
return
if(temp= BLANK(),[Stock],temp)

My formula can't replace previous blank records, so I use 'stock' measure to replace blank part.

 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.