Forum Discussion
Numerous Subtotals Formula
Hey Everybody!
I have the following data:
Type / Units
A / 100
B / 200
C / 300
Is there a formula that will allow me to show the following in a Matrix:
Type/Units
A / 100
B / 200
C / 300
A+B / 300
A+B+C / 600
Thanks in advance!
mibu
22 Replies
- MFelixSuper User
Hi mibu ,
Create a new table with the following format
CAT ID
A 1 B 2 C 3 A+B 4 A+B+C 5 Now add the following measure to your model.
CALCULATION = SWITCH ( TRUE (); MAX ( CAT[ID] ) < 4; CALCULATE ( SUM ( 'Table'[Units] ); 'Table'[Type] = VALUES ( CAT[CAT] ) ); MAX ( CAT[ID] ) = 4; CALCULATE ( SUM ( 'Table'[Units] ); FILTER ( ALL ( 'Table'[Type] ); 'Table'[Type] IN { "a"; "B" } ) ); CALCULATE ( SUM ( 'Table'[Units] ); ALL ( 'Table'[Type] ) ) )Then use the previous table information and the measure to create your matrix.
Regards,
MFelix
- mibuMicrosoft Employee
Hi MFelix
Is it possible to approach the problem in this way:
Create a new table as follows (table and .pbix file ABCTEST uploaded to dropbox here
And then come up with a Calculation/Measure/Formula that allows us to show the following in a single MATRIX:
A through H… each in its own Row (alphabetically)…
A+B… in its own Row (below row B)…
C+D+E … in its own Row (below row E)…
A+B+C+D+E... in its own Row (below C+D+E Subtotal row)...
A+B+C+D+E+F... in its own Row (below row F)...
G+H… in its own Row (below row H)…
Thanks!
Mibu
- Nathaniel_CCommunity Champion
mibu ,
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
NathanielSum A+ B, or sum A+B+C = var _A = Calculate(SUM(myTable[Units]),ALLEXCEPT(myTable,myTable[Type ]),myTable[Type ]= "A") var _B = Calculate(SUM(myTable[Units]),ALLEXCEPT(myTable,myTable[Type ]),myTable[Type ]= "B") var _C = Calculate(SUM(myTable[Units]),ALLEXCEPT(myTable,myTable[Type ]),myTable[Type ]= "C") //var _AB = (myTable[Type ] = "A"|| myTable[Type ] = "B", myTable[Units])) return IF(MAX(myTable[Type ])="B",_A+_B, If(MAX(myTable[Type ]) = "C", _A+_B+ _C))- mibuMicrosoft Employee
Nathaniel_C Thanks for your post! I am currently reviewing your proposed solution. very best, mibu
- mibuMicrosoft Employee
Hi Nathaniel_C
Expanding the scope a bit... to be more in line with the problem I am trying to solve.
Here is a faux sample set that resembles the eight variables I am working with... you can see your A+B and A+B+C solutions in Column AB/ABC:
Here is the output and matrix format I am trying to achieve:
Thanks in advance for your feedback about trying to solve this problem. I am aware that Subtotals/Row subtotals toggled On will sum Grand Total.
Thanks!
mibu
- Nathaniel_CCommunity Champion
Hi mibu ,
What are you trying to do? This looks like something that you won't be able to solve in Power BI alone. Might you provide us with a pbix. I think you will need to create other tables as well.
Thank you,Nathaniel
- v-xicaiCommunity Support
Hi mibu ,
You can create measure to get cumulative total like DAX below, then put it into Values box of Matrix visual.
Cumulative total = CALCULATE(SUM(Table1[Units]),FILTER(ALLSELECTED(Table1), Table1[Type] <=MAX(Table1[Type])))Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.