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

Get Fabric certified for FREE! Don't miss your chance! Learn more

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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

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.