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 September 15. Request your voucher.

Reply
admera
Frequent Visitor

Stock reduction based on demand (2)


Dear All Mastah

Hii everyone I don't have any idea for this measure about inventory, please help. I want to get the results from reducing stock to demand. The point is that the stock calculation will decrease if there is demand on each date. please check table my expectations

I have 2 table fact. table demand & table stock.

Table Demand

ArticleCodeDate DemandDemand
A00101-Mar200
A00102-Mar300
A00103-Mar200
A00104-Mar100
A00201-Mar 200 
A00202-Mar 300 
A00203-Mar 4,400 
A00204-Mar 11 
A00205-Mar 131 
A00206-Mar 131 
A00207-Mar 313 
A00208-Mar 131 
A00303-Mar200
A00304-Mar100
A00305-Mar 200 
A00306-Mar 300 
A00307-Mar 1,000 
A00308-Mar 900 

 

Table Stock

ArticleCodeStock
A001 10,000 
A002 9,000 
A003 5,000 

 

My Expectation Matrix

Matrix Expectation.jpg

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1716918706054.png

 

 

 

Jihwan_Kim_0-1716918599094.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Balance: = 
VAR _demandcumulate =
    CALCULATE (
        SUM ( Demand[Demand] ),
        WINDOW (
            1,
            ABS,
            0,
            REL,
            ALL ( Date_demand[Date Demand] ),
            ORDERBY ( Date_demand[Date Demand], ASC )
        )
    )
RETURN
    IF (
        HASONEVALUE ( Stock[ArticleCode] ) && HASONEVALUE ( Date_demand[Date Demand] ),
        MAXX ( Stock, Stock[Stock] ) - _demandcumulate
    )

 

Stock: = 
VAR _demandcumulatepreviousdate =
    CALCULATE (
        SUM ( Demand[Demand] ),
        WINDOW (
            1,
            ABS,
            -1,
            REL,
            ALL ( Date_demand[Date Demand] ),
            ORDERBY ( Date_demand[Date Demand], ASC )
        )
    )
RETURN
    IF (
        HASONEVALUE ( Stock[ArticleCode] ) && HASONEVALUE ( Date_demand[Date Demand] ),
        MAXX ( Stock, Stock[Stock] ) - _demandcumulatepreviousdate
    )

 

Demand: = 
IF (
    HASONEVALUE ( Stock[ArticleCode] ) && HASONEVALUE ( Date_demand[Date Demand] ),
    SUM ( Demand[Demand] )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1716918706054.png

 

 

 

Jihwan_Kim_0-1716918599094.png

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Balance: = 
VAR _demandcumulate =
    CALCULATE (
        SUM ( Demand[Demand] ),
        WINDOW (
            1,
            ABS,
            0,
            REL,
            ALL ( Date_demand[Date Demand] ),
            ORDERBY ( Date_demand[Date Demand], ASC )
        )
    )
RETURN
    IF (
        HASONEVALUE ( Stock[ArticleCode] ) && HASONEVALUE ( Date_demand[Date Demand] ),
        MAXX ( Stock, Stock[Stock] ) - _demandcumulate
    )

 

Stock: = 
VAR _demandcumulatepreviousdate =
    CALCULATE (
        SUM ( Demand[Demand] ),
        WINDOW (
            1,
            ABS,
            -1,
            REL,
            ALL ( Date_demand[Date Demand] ),
            ORDERBY ( Date_demand[Date Demand], ASC )
        )
    )
RETURN
    IF (
        HASONEVALUE ( Stock[ArticleCode] ) && HASONEVALUE ( Date_demand[Date Demand] ),
        MAXX ( Stock, Stock[Stock] ) - _demandcumulatepreviousdate
    )

 

Demand: = 
IF (
    HASONEVALUE ( Stock[ArticleCode] ) && HASONEVALUE ( Date_demand[Date Demand] ),
    SUM ( Demand[Demand] )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hii Kim

 

I have problem with this measure when I have hierarchy under Article Code, lets say Article Code Detail. if I breakdown by hierarchy Article Code Detail its not correct. can you help me to re-write dax Kim? thanks before

sample
A001
 A001-1

 A001-2

 A001-3

A002
 A002-1

 A002-2

 A002-3

Hi,

I am not 100% sure if I understood your question correctly, but if you are adding hierarchy, I think you also need to re-define stock data.

Please provide sample data model with re-defined information, and then I can try to look into it.

Thank you.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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