Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi community,
I'm pretty new to Power BI and Dax and pretty frustrated because I'm not able so solve this problem even after hours of googeling (I found forum posts (e.g. here and here ) which were related to my problem but I wasn't able to apply the solutions). I would really appreciate your help.
Scenario:
I want to predict the development of my inventory. I know how many items are in stock at the moment and I know when a specific amount of a specific product will be withdrawn.
My Goal:
I want to know on which day the inventory for a given product will drop below zero. Therefore I want to create a calculated column (or a measure, you tell me) for the product dimension table where this date is displayed.
Test Data:
I created a test pbix (Link) to showcase my problem.
Relationships:
dim Date 1 -- * Fact Transactions * -- 1 dim Products
I created a running total/cummulative total measure using the standard formula:
The Transactions Table looks like this. The positive numbers represent the current stock (today is the 3rd of June) while the negative numbers below represent future withdrawals.
Date | Quantity | Product |
03.06.2020 | 10 | A |
03.06.2020 | 10 | B |
04.06.2020 | -2 | A |
05.06.2020 | -2 | B |
06.06.2020 | -2 | A |
07.06.2020 | -3 | B |
08.06.2020 | -3 | A |
09.06.2020 | -3 | B |
10.06.2020 | -3 | A |
11.06.2020 | -4 | B |
12.06.2020 | -4 | A |
And the result I want to see in my Dim Products Table looks like this:
Product ID | Runs out on |
A | 10.06.2020 |
B | 11.06.2020 |
I appreciate the help. Thank you in advance.
Lucas
Solved! Go to Solution.
@Anonymous try following measure:
Stock Run Out Date =
VAR __date = CALCULATETABLE( FILTER( ALL ( 'Dim Date'[Date] ), 'Dim Date'[Date] <= MAX ( 'Dim Date'[Date] ) ) )
VAR __data =
SUMMARIZE (
CROSSJOIN (
VALUES ( 'Dim Products'[Product ID] ),
__date
),
'Dim Products'[Product ID],
'Dim Date'[Date],
"__cumulative Quantity", [Cumulative Quantity],
"__cumulative Is Blank", [Cumulative Quantity] ==BLANK()
)
RETURN
MINX (
FILTER (
__data,
[__cumulative Quantity] <=0 &&
NOT [__cumulative Is Blank]
),
[Date]
)
And here is the output
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@Anonymous try following measure:
Stock Run Out Date =
VAR __date = CALCULATETABLE( FILTER( ALL ( 'Dim Date'[Date] ), 'Dim Date'[Date] <= MAX ( 'Dim Date'[Date] ) ) )
VAR __data =
SUMMARIZE (
CROSSJOIN (
VALUES ( 'Dim Products'[Product ID] ),
__date
),
'Dim Products'[Product ID],
'Dim Date'[Date],
"__cumulative Quantity", [Cumulative Quantity],
"__cumulative Is Blank", [Cumulative Quantity] ==BLANK()
)
RETURN
MINX (
FILTER (
__data,
[__cumulative Quantity] <=0 &&
NOT [__cumulative Is Blank]
),
[Date]
)
And here is the output
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Thank you @parry2k . That measure did the trick. Allow me to ask a follow up question: What are the advantages of using a measure instead of calculated column here?
@Anonymous great question. read this post
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
User | Count |
---|---|
103 | |
88 | |
78 | |
71 | |
69 |
User | Count |
---|---|
113 | |
99 | |
97 | |
72 | |
68 |