Forum Discussion
Please help for stock problem
Hello everyone,
I have given the following table. When I sort the table by date in Power BI, this comes up. The order is absolutely correct and is exactly what it is supposed to be.
I created the custom index with Power query
current situation:
| ID | ProductID | Nr | Date | Quantity | Art | Input | Output | Stock | accumulated Stock | Index | Customer | |||||||||||
| 123 | 123 | 1 | 26.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 75 | 1281 | L | |||||||||||
| 123 | 123 | 1 | 26.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 73 | 1282 | M | |||||||||||
| 123 | 123 | 1 | 27.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 311 | 1284 | N | |||||||||||
| 123 | 123 | 1 | 27.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 305 | 1286 | O | |||||||||||
| 123 | 123 | 1 | 27.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 303 | 1287 | P | |||||||||||
| 1084807 | 123 | 1 | 27.04.2022 00:00:00 | 4 | Output | 0 | 4 | -4 | 307 | 1285 | Q | |||||||||||
| 123 | 123 | 2 | 27.04.2022 09:15:33 | 100 | Input | 100 | 0 | 100 | 313 | 1283 | R | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 301 | 1289 | S | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 302 | 1288 | T | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 300 | 1290 | U | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 299 | 1291 | V |
expected situation:
| ID | ProductID | Nr | Date | Quantity | Art | Input | Output | Stock | accumulated Stock | Index | Customer | |||||||||||
| 123 | 123 | 1 | 26.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 75 | 1281 | L | |||||||||||
| 123 | 123 | 1 | 26.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 73 | 1282 | M | |||||||||||
| 123 | 123 | 1 | 27.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 71 | 1284 | N | |||||||||||
| 123 | 123 | 1 | 27.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 69 | 1286 | O | |||||||||||
| 123 | 123 | 1 | 27.04.2022 00:00:00 | 2 | Output | 0 | 2 | -2 | 67 | 1287 | P | |||||||||||
| 123 | 123 | 1 | 27.04.2022 00:00:00 | 4 | Output | 0 | 4 | -4 | 63 | 1285 | Q | |||||||||||
| 123 | 123 | 2 | 27.04.2022 09:15:33 | 100 | Input | 100 | 0 | 100 | 303 | 1283 | R | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 302 | 1289 | S | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 301 | 1288 | T | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 300 | 1290 | U | |||||||||||
| 123 | 123 | 1 | 28.04.2022 00:00:00 | 1 | Output | 0 | 1 | -1 | 299 | 1291 | V |
Hi azaterol ,
Has your problem been solved? According to your snapshot, if you want to calculate the accumulated stock based on the date and ID, as you have create a index column seams based on date, you can simply create a measure:
Accumulated Stock = SUMX ( FILTER ( ALL ( 'Table' ), 'Table'[ID] = MAX ( 'Table'[ID] ) && 'Table'[Index] <= MAX ( 'Table'[Index] ) ), [Stock] )Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- v-yanjiang-msft
Community Support
Hi azaterol ,
Has your problem been solved? According to your snapshot, if you want to calculate the accumulated stock based on the date and ID, as you have create a index column seams based on date, you can simply create a measure:
Accumulated Stock = SUMX ( FILTER ( ALL ( 'Table' ), 'Table'[ID] = MAX ( 'Table'[ID] ) && 'Table'[Index] <= MAX ( 'Table'[Index] ) ), [Stock] )Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ryan_mayu
Super User
how do you get the initial stock? where does the 75 come from?