Forum Discussion
Stock reduction based on demand (2)
- 2 years ago
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.
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] ) )
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.
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] )
)
- admera2 years agoFrequent Visitor
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-1A001-2
A001-3
A002
A002-1A002-2
A002-3
- Jihwan_Kim2 years ago
Super User
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.