Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hello , i have a simple problem but i cant find a simple answer :
I tried to look on older posts but i couldnt find a solution to mi problem :
I have a model where i have :
Sales in : the sales from mi compañy to resellers
Sales Out: the sales from the resellers to end users
Initial stock : the stock on hand reported by the resellers at 01/01/2020
I need to calculate the stock by adding the sell in and sustracting the sell out :
Example :
initial stock productA in reseller A =10000 to that value i have to add the sell in and sustract the sell out
01/01/2020 stock=10000
sales in jan/2020=5000
Sales out in jan/2020=7000
stock in feb/2020= 10000+5000-7000=8000<then , this should be the initial stock in february so :
sales in feb/2020=2000
sales out feb/2020=5000
stock in march/2020=8000+2000-5000=5000 , and so on
i have a sales in table with dates and sku and reseller number , also i have a sales out table with the same dimentions , calendar table , and product table
TY!!!
You can calculate monthly or daily stock balances in Power BI using cumulative DAX measures.
Model Assumption:
SalesIn → stock received
SalesOut → stock issued
InitialStock → opening quantity
Calendar → connected to both SalesIn and SalesOut tables by Date
Base Measures
Total Sales In = SUM(SalesIn[Quantity])
Total Sales Out = SUM(SalesOut[Quantity])
Initial Stock = SUM(InitialStock[InitialStock])Cumulative and Stock
Stock =
[Initial Stock] +
CALCULATE([Total Sales In], FILTER(ALLSELECTED('Calendar'[Date]), 'Calendar'[Date] <= MAX('Calendar'[Date]))) -
CALCULATE([Total Sales Out], FILTER(ALLSELECTED('Calendar'[Date]), 'Calendar'[Date] <= MAX('Calendar'[Date])))
Go to Model view → New Table, then paste:
ExampleStock =
DATATABLE(
"Month", STRING,
"MonthOrder", INTEGER,
"Initial", INTEGER,
"Sales In", INTEGER,
"Sales Out", INTEGER,
"Stock", INTEGER,
{
{"Jan", 1, 10000, 5000, 7000, 8000},
{"Feb", 2, 0, 2000, 5000, 5000},
{"Mar", 3, 0, 3000, 1000, 7000}
}
)
Hope this helps!
Model setup
Measures
Sales In Qty =
SUM('Sales In'[Qty])
Sales Out Qty =
SUM('Sales Out'[Qty])
Net Movement =
[Sales In Qty] + [Sales Out Qty] * COS(PI())
Initial Stock Qty =
COALESCE(SUM('Initial Stock'[Qty]), 0)
Cumulative Net Movement since 2020 01 01 =
VAR Anchor = DATE(2020, 1, 1)
RETURN
CALCULATE(
[Net Movement],
FILTER(
ALLSELECTED('Date'[Date]),
'Date'[Date] >= Anchor && 'Date'[Date] <= MAX('Date'[Date])
)
)
Stock On Hand by date =
[Initial Stock Qty] + [Cumulative Net Movement since 2020 01 01]
Stock at month end for visuals grouped by month =
VAR LastDay = EOMONTH(MAX('Date'[Date]), 0)
RETURN
CALCULATE(
[Stock On Hand by date],
KEEPFILTERS('Date'[Date] = LastDay)
)
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 6 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 25 | |
| 16 | |
| 8 | |
| 8 | |
| 8 |