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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Gjakova
Post Patron
Post Patron

How to calculate the daily inventory?

Hi there, I am struggling with the following issue:

I need to calculate the inventory for each date which is based on the result of previous day. Thus I for example on January 1st I have 10 iPhones left and my store purchases 5 more, I sell 9 iPhones on that same day which leaves me with 10 + 5 - 9 = 6 iPhones. On January 2nd I start with 6 iPhones, I buy 3 and sell 7 which leaves me with 6 + 3 - 7 = 2 iPhones, on January 3rd I thus start with 2 iPhones and the process gets repeated. The table looks like this:

ProductDateBase StockOpeningPurchasedSoldClosing Inventory
iPhoneJanuary 1st1010596
iPhoneJanuary 2nd/6372
iPhoneJanuary 3rd/220517
Apple WatchJanuary 1st707054035

 

My model looks like this:

Gjakova_0-1621777716932.png

I was thinking of creating one table, but the problem is that it would be MORE THAN 50 MILLION ROWS! in my real dataset.

Basically, when I select a product and a date with my slicer, I want to see how many products I have left on a certain date.

My Basic Stock table has the starting stock on January 1st for all my products, I only use that once (to see how many products I have when I start counting (only 01-01-20xx). So January 1st, 2020 looks at Basic Stock, but January 1st, 2021 looks at December 31, 2020.

Furthermore, the purchase of certain items can differ with selling it on a certain item. So if I buy 5 iPhones on April 1st, 2020, it does not mean that I sell thatm on April 1st, 2020 but I could sell them on April 8, 2020 or another date.

The main problem for me is how to calculate with a measure what my Closing Inventory is, especially when the Opening of a products needs to look at the Closing Inventory of the previous date.

Here is a sample of my PBIX: https://www.dropbox.com/s/nkpu4vxj2hvirg8/Inventory%20Issue.pbix?dl=0

Happy to hear how this would be best solved!

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Gjakova ,

 

First disable all relationship between your fact table to calendar table. Then you can use the following measure:

 

Purchased = CALCULATE(SUM(Purchases[Quantity]),FILTER(Purchases,Purchases[Purchase Date]<=MAX('Calendar'[Date])))

Sold = CALCULATE(SUM(Sales[Quantity]),FILTER(Sales,Sales[Sales Date]<=MAX('Calendar'[Date]))) 

Closing Inventory = MAX('Basic Stock'[Quantity])+[Purchased]-[Sold]

 

Capture.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

View solution in original post

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @Gjakova ,

 

First disable all relationship between your fact table to calendar table. Then you can use the following measure:

 

Purchased = CALCULATE(SUM(Purchases[Quantity]),FILTER(Purchases,Purchases[Purchase Date]<=MAX('Calendar'[Date])))

Sold = CALCULATE(SUM(Sales[Quantity]),FILTER(Sales,Sales[Sales Date]<=MAX('Calendar'[Date]))) 

Closing Inventory = MAX('Basic Stock'[Quantity])+[Purchased]-[Sold]

 

Capture.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

Hi @v-deddai1-msft thank you! I will try it ASAP and let you know. One question though... what is the reason that the relationship between my calendar and fact table should be disabled? Kind regards!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.