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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

STOCK FLOW

Hello everyone, how are you?

I develop a project whose objective is to calculate the stock of certain customers using 3 tables.

fPurchases, fSales and fStock


I carried out some measures to return the balance between fPurchases and fSales, with this balance accumulated in the Closing measure and sent to the context of the next month in the Inventory of the Month measure.

Closing =
CALCULATE(
    [Purchases-Sales],
    FILTER(
        ALL(dCalendar[Date]),
        dCalendar[Date] <= MAX(dCalendar[Date])
    )
)
Inventory of the Month = CALCULATE([Closing], DATEADD(dCalendario[Date], -1, MONTH))


In other words, while purchases and sales occur throughout the month, the balance of this account will be determined until the last day of the filter context in the Closing measure, while the Inventory of the Month measure will transfer this result to the first day of the next month.

The purchase and sales tables do not capture complete information, and it is not possible to rely solely on them to calculate inventory.

This way, we have the fEstoque table with real stock data that is updated monthly, where, in most cases, it has different values ​​than the results of my measurements. The intention is to have the measurements I created adjusted by the difference between the stock that was calculated and the stock that was entered in fEstoque.

Ex: IF( [Stock of the Month] <> SUM(fStock[quantity], SUM(fStock[quantity], [Stock of the Month] )

A simple IF or SWITCH does not work, because in the following month the calculation stops considering SUM(fEstoque[quantidade] as the initial stock for the month.

Thank you very much to anyone who can give me some advice!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , You have try measures like

 

Onhand BOP= CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <min(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <min(date[date])))


onhand EOP= CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <=Max(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <= Max(date[date])))

 

If need add purcahse and sales

 

example

 

Inventory / OnHand =
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),filter(all(date),date[date] <min(date[date]))) +
CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <min(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <min(date[date])))


Inventory / OnHand =
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),filter(all(date),date[date] <=max(date[date]))) +
CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <=max(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <=max(date[date])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , You have try measures like

 

Onhand BOP= CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <min(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <min(date[date])))


onhand EOP= CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <=Max(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <= Max(date[date])))

 

If need add purcahse and sales

 

example

 

Inventory / OnHand =
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),filter(all(date),date[date] <min(date[date]))) +
CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <min(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <min(date[date])))


Inventory / OnHand =
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),filter(all(date),date[date] <=max(date[date]))) +
CALCULATE(SUM(Table[Ordered]),filter(all(date),date[date] <=max(date[date]))) -
CALCULATE(SUM(Table[Sold]),filter(all(date),date[date] <=max(date[date])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Hello friend

This way the same problem occurs. After a new load of data, with new months, the measure no longer considers the stock adjusted for the difference. I believe I need to create something like a loop.

But thanks

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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