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
v_mark
Helper V
Helper V

Calculate products used on a daily basis

Hello Everyone,

 

I have a simple table that has Quantity and Stock. The goal is to know how many products are being consumed on a daily basis. 
Here is the sample data table and desired result. Wondering how I can execute the desired result into a measure or calculated column using DAX or Power Query perhaps. 


Essentially this is how it was being computed in Excel.

 

v_mark_0-1692622808188.png

 

And below is the result it was giving. 

LOBWarehouseProductDate QuantityStockResult 
ATargetABD-115512413/04/20233118
BTargetABD-115512427/01/20231117
BTargetABD-115512405/04/20231116
BTargetABD-115512411/04/20231115
BTargetABD-115512427/04/20231114
BTargetABD-115512422/05/20231113
BTargetABD-115512419/06/20231112
BTargetABD-115512404/07/20231111
BTargetABD-115512419/07/20231110
BTargetABD-115512420/07/2023111-1
BTargetABD-115512401/08/2023111-2
1 ACCEPTED SOLUTION

@v_mark 
Please refer to attached sample file. See how it works with your real data and return back with your comments.

1.png

Result = 
VAR Stock = 'Table'[Stock]
VAR CurrentLOB = 'Table'[LOB]
VAR CurrentDate = 'Table'[Date]
VAR CurrentWarehoursProductTable = 
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Warehouse], 'Table'[Product] ) )
VAR TableBefore = 
    FILTER ( CurrentWarehoursProductTable, 'Table'[LOB] < CurrentLOB )
VAR TableOnAndBefore = 
    FILTER ( CurrentWarehoursProductTable, 'Table'[Date] <= CurrentDate && 'Table'[LOB] = CurrentLOB )
VAR QuantityBefore = 
    SUMX ( TableBefore, 'Table'[Quantity] )
VAR QuantityOnAndBefore = 
    SUMX ( TableOnAndBefore, 'Table'[Quantity] )
RETURN
    StocK - QuantityBefore - QuantityOnAndBefore

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @v_mark 
Can you update the sample including the date and the product? Are you trying to create a calculated column or a measure?

@tamerj1 - Sure I updated the original post. They have the same product all across and Warehouse. 
The difference they have is based in Dates and Line of business (LOB). 

@v_mark 
Why the quantity of LOB A which is (3) is subtracted twice? I mean shouldn't the result of the 2nd row be 7? What is the logic behind your expected result?

@tamerj1 'm sorry that is a mistake on my end.  As far creating measure or calculated column either way will work  I guess. The idea is to drag it over to a table in the report. 
You are right.. Ideally it should be 7 . Please see details below.

v_mark_0-1692622607392.png

 

I will update my post

@v_mark 
Please refer to attached sample file. See how it works with your real data and return back with your comments.

1.png

Result = 
VAR Stock = 'Table'[Stock]
VAR CurrentLOB = 'Table'[LOB]
VAR CurrentDate = 'Table'[Date]
VAR CurrentWarehoursProductTable = 
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Warehouse], 'Table'[Product] ) )
VAR TableBefore = 
    FILTER ( CurrentWarehoursProductTable, 'Table'[LOB] < CurrentLOB )
VAR TableOnAndBefore = 
    FILTER ( CurrentWarehoursProductTable, 'Table'[Date] <= CurrentDate && 'Table'[LOB] = CurrentLOB )
VAR QuantityBefore = 
    SUMX ( TableBefore, 'Table'[Quantity] )
VAR QuantityOnAndBefore = 
    SUMX ( TableOnAndBefore, 'Table'[Quantity] )
RETURN
    StocK - QuantityBefore - QuantityOnAndBefore

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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