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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
aoncirto
Frequent Visitor

Calculate Stock and demand based on material each day - Stock Planning

Aloha all, 🤙

 

After reading some topic, watched some youtubes and try talks with chatGPT. Still cant get the correct result. 😞 

 

I have multiple tables and one final in my powerBi report. the Final table have following items: 

DatePart_NumberDemandStock

2023-10-01

4ABC588-AD1025

2023-10-02

4ABC588-AD2025

2023-10-03

4ABC588-AD1525

The Column[Stock] is same for all Parts because i downloaded from ERP system(SAP) every Monday and connected to Part Number( that is the reason the same numbers) 

In Column[Part_Number] - there will be multiple parts not only one. 

 

What is my dream to have: 

 

Spoiler
DatePart_NumberDemandStockStock_Demand

2023-10-01

4ABC588-AD102515

2023-10-02

4ABC588-AD2025-5

2023-10-03

4ABC588-AD1525-20

behind the calculation: 

Take the first date of the one Part number and calculate [Stock] - [Demand] = 15
Take the result (15) - [Demand] = -5
(-5) - [Demand] = -20

etc.

 
Thank you in advance for any ideas
 
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@aoncirto 

As a best practice, add a date dimension in your model and use it for time intelligence calculations. Once the date dimension is added, mark it as a date table on table tools. Check the related videos on my YT channel

 

Add Date Dimension
Importance of Date Dimension
Mark date dimension as a date table - why and how?
Time Intelligence Playlist

 

Once you have date dimension, add following measures:

 

Total Demand = 
CALCULATE ( 
   SUM ( Table[Demand] ),
   FILTER ( 
      ALL ( 'Calendar'[Date] ),
      'Calendar'[Date] <= MAX ( 'Calendar'[Date] ) 
   )
)

Total Stock = MAX ( Table[Stock] )

Balance Stock = [Total Stock] - [Total Demand] 


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

7 REPLIES 7
parry2k
Super User
Super User

@aoncirto if you visualize it by date, you will get the correct result. Make sure you are adding a measure not a calculated column.



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.

Hello @parry2k
That was the issue about calc. column and measure. You have right, its works. Thank you so much. 

How it works the measure(the main one)

Calculate and SUM function will like summarize all the values under "Demand" Column and Filter just return the value each day? 

Once again Thank you

parry2k
Super User
Super User

@aoncirto how you are visualizing it? What columns you are using in the visual?



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.

The visualization Is not done yet. After the data will be ready.

aoncirto
Frequent Visitor

Hello @parry2k , 

 

I already have the "Calendar" table, but your solution not works the Column "Balance Stock" is -20 for all rows. I need to calculate each row. 

 

Thank you

 

 

parry2k
Super User
Super User

@aoncirto 

As a best practice, add a date dimension in your model and use it for time intelligence calculations. Once the date dimension is added, mark it as a date table on table tools. Check the related videos on my YT channel

 

Add Date Dimension
Importance of Date Dimension
Mark date dimension as a date table - why and how?
Time Intelligence Playlist

 

Once you have date dimension, add following measures:

 

Total Demand = 
CALCULATE ( 
   SUM ( Table[Demand] ),
   FILTER ( 
      ALL ( 'Calendar'[Date] ),
      'Calendar'[Date] <= MAX ( 'Calendar'[Date] ) 
   )
)

Total Stock = MAX ( Table[Stock] )

Balance Stock = [Total Stock] - [Total Demand] 


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.

Hello @parry2k

Its there way how to just start the measure calculate from "last Monday" to "next Monday" in current week. 

 I try this but do not works 😕 

MeasureStock_Monday = 
CALCULATE(MAX([Stock_Sum],FILTER('Calendar','Calendar'[Day Name] = "Monday")))

Thank you so much 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.