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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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