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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calculate Date when Running Total hits target

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:

 

Cumulative Quantity =
CALCULATE (
  SUM ( 'Fact Future Transactions'[Quantity]);
  FILTER (
    ALL ( 'Dim Date'[Date] );
    'Dim Date'[Date] <= MAX ( 'Dim Date'[Date] )
)
)

 

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.

 

DateQuantityProduct
03.06.202010A
03.06.202010B
04.06.2020-2A
05.06.2020-2B
06.06.2020-2A
07.06.2020-3B
08.06.2020-3A
09.06.2020-3B
10.06.2020-3A
11.06.2020-4B
12.06.2020-4A

 

And the result I want to see in my Dim Products Table looks like this:

 

Product IDRuns out on
A10.06.2020
B11.06.2020

 

I appreciate the help. Thank you in advance.

 

Lucas

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@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


image.png

 

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.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@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


image.png

 

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
Not applicable

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.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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