Forum Discussion
Running Total By Product
I need help with Running Totals by Product in Power BI using DAX.
Please see attached Example data. There are 3 levels in this Example: 1st Level is Store, 2nd Level is the Product, 3rd Level is the Sub Category.
The Running total will need to be calculated only at the Product Level (2nd level). If the row is a Store (1st Level) , the Running total will just be the Total from the Amount. If the row is a Sub Product (3rd), the Running Total will need to be 0.
| Store | Amt | Sequence | RT - On Product |
| Store1 | 20,513 | 20,513 | |
| Product 1 | 4,136 | 1 | 4,136 |
| Product 1 - Sub Cat A | 19,030 | 1 | 0 |
| Product 1 - Sub Cat B | 200 | 1 | 0 |
| Product 1 - Sub Cat C | -1,092 | 1 | 0 |
| Product 1 - Sub Cat D | -13,500 | 1 | 0 |
| Product 1 - Sub Cat E | -502 | 1 | 0 |
| Product 1 - Sub Cat F | 0 | 1 | 0 |
| Product 2 | 248,198 | 2 | 252,334 |
| Product 3 | 0 | 3 | 252,334 |
| Product 4 | 524,854 | 4 | 777,188 |
| Product 5 | 152,326 | 5 | 929,514 |
| Product 6 | 20,675 | 6 | 950,189 |
| Product 7 | 225 | 7 | 950,414 |
Hi lyrk8888 ,
Try formula like below:
Level = VAR search_ = SEARCH ( "*Sub", 'Table'[Store],, 0 ) RETURN IF ( 'Table'[Store] = "Store1", "level1", IF ( search_ = 1, "level3", "level2" ) )M_ = IF ( MAX ( 'Table'[Level] ) = "level1", MAX ( 'Table'[Amt] ), IF ( MAX ( 'Table'[Level] ) = "level3", 0, CALCULATE ( SUM ( 'Table'[Amt] ), ALLEXCEPT ( 'Table', 'Table'[Level] ) ) ) )If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 Reply
- v-henryk-mstfCommunity Support
Hi lyrk8888 ,
Try formula like below:
Level = VAR search_ = SEARCH ( "*Sub", 'Table'[Store],, 0 ) RETURN IF ( 'Table'[Store] = "Store1", "level1", IF ( search_ = 1, "level3", "level2" ) )M_ = IF ( MAX ( 'Table'[Level] ) = "level1", MAX ( 'Table'[Amt] ), IF ( MAX ( 'Table'[Level] ) = "level3", 0, CALCULATE ( SUM ( 'Table'[Amt] ), ALLEXCEPT ( 'Table', 'Table'[Level] ) ) ) )If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.