Don't miss your chance to take exam DP-600 or DP-700 on us!
Request nowLearn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hello, we have a table where all the movements are by item/date/types of movement and we need to calculate the accumulated stock to later calculate the average cost.
This is the formula we have:
Ending Balance2 =
VAR DateEnd=MAX(Movements[DateIssue])
Total VAR= CALCULATE(sum(Movements[Mov Existence]),FILTER(ALLSELECTED(Movements[IssueDate]),Movements[IssueDate]<=Enddate))
RETURN total
But the accumulated is being given to us by type of movement, how could the formula be modified so that the total is taken out for each line without considering the movement?
An index cannot be included in the table as such because there are many items and they have different movements on different dates.
Thank you very much in advance
Solved! Go to Solution.
Hi @Syndicate_Admin
Please try the following Dax:
PreviousMonthOpeningBalance =
VAR PreviousMonthBalance =
CALCULATE(
[WarehouseBalance],
FILTER(
ALL(Calendar),
Calendar[Date] < MIN(Calendar[Date])
)
)
RETURN PreviousMonthBalance
EndingBalance222 =
VAR _index = SELECTEDVALUE(Movements[Last Change])
VAR _artical = SELECTEDVALUE(Movements[Item])
VAR PreviousMonthBalance = [PreviousMonthOpeningBalance]
VAR Total =
CALCULATE(
[WarehouseBalance],
FILTER(
ALL(Movements),
Movements[Last Change] <= _index && Movements[Item] = _artical
)
)
RETURN
IF(
_index = MINX(ALL(Movements), Movements[Last Change]),
PreviousMonthBalance + Total,
Total
)
If the above dax can't help you solve your problem, can you provide detailed sample pbix file and the results you expect.So that I can help you better. Please remove any sensitive data in advance.
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hey, hey, hey, it's good.
Thank you very much, from which option can I attach the PBIX file?
Please provide sample data that fully covers your issue(in the form of pbix file or table) and the expected outcome based on the sample data you provided.So that I can help you better. Please remove any sensitive data in advance.
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
| Article | Mov | LastChange | Mov Existence | ID | DateIssue |
| 01 5930 | 2.1 Invoice | 04/06/2024 16:45 | -20 | 184214 | 04/06/2024 |
| 01 5930 | 2.1 Invoice | 06/06/2024 15:49 | -40 | 184195 | 06/06/2024 |
| 01 5930 | 5.3 Miscellaneous Input | 10/07/2024 14:36 | 40 | 105465 | 10/07/2024 |
| 01 5930 | 2.1 Invoice | 10/07/2024 14:38 | -60 | 185178 | 10/07/2024 |
| 01 5930 | 3.2 Import Entry | 30/07/2024 13:00 | 980 | 26403 | 30/07/2024 |
| 01 5930 | 5.2 Transfer | 30/07/2024 14:25 | -20 | 105849 | 30/07/2024 |
| 01 5930 | 5.2 Transfer | 30/07/2024 14:25 | 20 | 105849 | 30/07/2024 |
| 01 5930 | 3.2 Import Entry | 30/07/2024 15:36 | 1400 | 26405 | 30/07/2024 |
| 01 5930 | 2.1 Invoice | 02/08/2024 13:43 | -100 | 185864 | 02/08/2024 |
| 01 5930 | 2.1 Invoice | 05/08/2024 16:24 | -80 | 185917 | 05/08/2024 |
| 01 5930 | 2.1 Invoice | 06/08/2024 14:55 | -160 | 185934 | 06/08/2024 |
| 01 5930 | 5.2 Transfer | 06/08/2024 16:39 | -200 | 105981 | 06/08/2024 |
| 01 5930 | 5.2 Transfer | 06/08/2024 16:39 | 200 | 105981 | 06/08/2024 |
| 01 5930 | 2.1 Invoice | 07/08/2024 15:00 | -200 | 185968 | 07/08/2024 |
| 02 0092 | 2.1 Invoice | 03/06/2024 09:08 | -360 | 184129 | 03/06/2024 |
| 02 0092 | 2.1 Invoice | 03/06/2024 09:08 | -640 | 184129 | 03/06/2024 |
| 02 0092 | 2.1 Invoice | 03/06/2024 13:14 | -60 | 184125 | 03/06/2024 |
| 02 0092 | 5.1 Material consumption | 04/06/2024 09:20 | -205.5 | 104890 | 04/06/2024 |
| 02 0092 | 2.1 Invoice | 05/06/2024 15:07 | -1500 | 184174 | 05/06/2024 |
| 02 0092 | 2.1 Invoice | 06/06/2024 13:57 | -600 | 184251 | 06/06/2024 |
| 02 0092 | 2.1 Invoice | 06/06/2024 14:27 | -1000 | 184249 | 06/06/2024 |
| 02 0092 | 5.1 Material consumption | 07/06/2024 10:01 | -320.6 | 104976 | 07/06/2024 |
| 02 0092 | 2.1 Invoice | 07/06/2024 10:57 | -1640 | 184319 | 07/06/2024 |
| 02 0092 | 2.1 Invoice | 07/06/2024 11:04 | -2000 | 184322 | 07/06/2024 |
| 02 0092 | 2.1 Invoice | 01/07/2024 09:17 | -1000 | 184889 | 01/07/2024 |
| 02 0092 | 5.2 Transfer | 01/07/2024 14:43 | -20 | 105323 | 01/07/2024 |
| 02 0092 | 5.2 Transfer | 01/07/2024 14:43 | -100 | 105323 | 01/07/2024 |
| 02 0092 | 2.1 Invoice | 02/07/2024 11:03 | -2000 | 184939 | 02/07/2024 |
| 02 0092 | 3.2 Import Entry | 02/07/2024 16:23 | 5600 | 26322 | 02/07/2024 |
| 02 0092 | 3.2 Import Entry | 02/07/2024 16:23 | 15400 | 26322 | 02/07/2024 |
| 02 0092 | 2.1 Invoice | 01/08/2024 11:31 | -1000 | 185791 | 01/08/2024 |
| 02 0092 | 2.1 Invoice | 01/08/2024 14:08 | -800 | 185795 | 01/08/2024 |
| 02 0092 | 2.1 Invoice | 01/08/2024 14:13 | -1000 | 185810 | 01/08/2024 |
| 02 0092 | 5.4 Miscellaneous Output | 01/08/2024 14:15 | -20 | 105937 | 01/08/2024 |
| 02 0092 | 2.1 Invoice | 02/08/2024 13:25 | -1000 | 185861 | 02/08/2024 |
| 02 0092 | 2.1 Invoice | 05/08/2024 11:50 | -3500 | 185869 | 05/08/2024 |
| 02 0092 | 2.1 Invoice | 05/08/2024 16:15 | -3000 | 185877 | 05/08/2024 |
| 02 0092 | 3.2 Import Entry | 06/08/2024 11:55 | 2800 | 26432 | 06/08/2024 |
| 02 0092 | 3.2 Import Entry | 06/08/2024 11:55 | 7000 | 26432 | 06/08/2024 |
| 02 0092 | 2.1 Invoice | 06/08/2024 13:14 | -1500 | 185940 | 06/08/2024 |
| 02 0092 | 5.2 Transfer | 06/08/2024 14:16 | -4200 | 105980 | 05/08/2024 |
| 02 0092 | 5.2 Transfer | 06/08/2024 14:16 | 4200 | 105980 | 05/08/2024 |
| 02 0092 | 2.1 Invoice | 06/08/2024 15:03 | -100 | 185900 | 06/08/2024 |
| 02 0092 | 2.1 Invoice | 06/08/2024 15:10 | -2000 | 185913 | 06/08/2024 |
| 02 0092 | 2.1 Invoice | 07/08/2024 13:18 | -2000 | 185964 | 07/08/2024 |
| 02 0092 | 5.1 Material consumption | 14/08/2024 10:11 | -685 | 106075 | 14/08/2024 |
| 02 0092 | 5.1 Material consumption | 14/08/2024 15:10 | -14767.5 | 106105 | 14/08/2024 |
| 02 0092 | 5.1 Material consumption | 14/08/2024 15:10 | -527.5 | 106105 | 14/08/2024 |
| 02 0092 | 2.1 Invoice | 16/08/2024 11:46 | -1500 | 186203 | 16/08/2024 |
| 02 0092 | 5.2 Transfer | 16/08/2024 17:04 | -20 | 106160 | 16/08/2024 |
| 02 0092 | 5.2 Transfer | 16/08/2024 17:04 | 20 | 106160 | 16/08/2024 |
| 02 0092 | 2.1 Invoice | 19/08/2024 14:15 | -400 | 186246 | 19/08/2024 |
| 02 0092 | 2.1 Invoice | 19/08/2024 14:43 | -40 | 186249 | 19/08/2024 |
Hi @Syndicate_Admin
First, create an index column in power query:
Then, you can try the following dax to get the result you want:
Ending Balance2 =
VAR _index = SELECTEDVALUE(Movements[Index])
VAR total= CALCULATE(SUM(Movements[Mov Existence]),FILTER(ALL(Movements),'Movements'[Index] <= _index))
RETURN total
Result:
If you want to categorize by article, you can try the following dax:
Ending Balance22 =
VAR _index = SELECTEDVALUE(Movements[Index])
VAR _artical = SELECTEDVALUE(Movements[Article])
VAR total= CALCULATE(SUM(Movements[Mov Existence]),FILTER(ALL(Movements),'Movements'[Index] <= _index && 'Movements'[Article] = _artical))
RETURN total
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you very much for your support, I took the information you sent as a basis and it worked 🙂 . I only made a modification in the formula of Ending Balance 22 so that it would take the value you selected in the segmenter.
Hi @Syndicate_Admin
Please try the following Dax:
PreviousMonthOpeningBalance =
VAR PreviousMonthBalance =
CALCULATE(
[WarehouseBalance],
FILTER(
ALL(Calendar),
Calendar[Date] < MIN(Calendar[Date])
)
)
RETURN PreviousMonthBalance
EndingBalance222 =
VAR _index = SELECTEDVALUE(Movements[Last Change])
VAR _artical = SELECTEDVALUE(Movements[Item])
VAR PreviousMonthBalance = [PreviousMonthOpeningBalance]
VAR Total =
CALCULATE(
[WarehouseBalance],
FILTER(
ALL(Movements),
Movements[Last Change] <= _index && Movements[Item] = _artical
)
)
RETURN
IF(
_index = MINX(ALL(Movements), Movements[Last Change]),
PreviousMonthBalance + Total,
Total
)
If the above dax can't help you solve your problem, can you provide detailed sample pbix file and the results you expect.So that I can help you better. Please remove any sensitive data in advance.
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Good day, thank you very much, if it worked for me. 👍
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 55 | |
| 49 | |
| 33 | |
| 16 | |
| 15 |
| User | Count |
|---|---|
| 85 | |
| 70 | |
| 38 | |
| 28 | |
| 25 |