Forum Discussion
Matrix Adding total from previous Group
- 3 months ago
Hi nagendranath,
Thank you for reaching out to Microsoft Fabric Community Forum.
The requirement is for a cumulative or running total across groups, not just a standard group subtotal.For instance:
- Total Machinist = 475
- Total Machinist Including Trainee = 475 + 13 = 488
This means each subsequent group should include the totals from the preceding groups.
This result can't be achieved with only Matrix grouping or subtotal options. Instead, you should use a Running Total measure in DAX.
First Create an Order column
Assign a numeric order to your groups so Power BI can determine the sequence.
Example:
GroupOrderMachinist1Machinist Including Trainee2Supervisor3Supervisor Including Trainee4
Ensure the Group column is sorted by the Order column.
Next Build the Running Total MeasureRunning Total =
VAR CurrentRank =
MAX ( 'Table'[Order] )
RETURN
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER (
ALL ( 'Table'[Group], 'Table'[Order] ),
'Table'[Order] <= CurrentRank
)
)Later Apply the Measure in Matrix
Replace the current total measure in your Matrix visual with this new Running Total measure.
The result will be:
- Machinist = 475
- Machinist Including Trainee = 488
- Each following group = Previous total + Current group total
This method offers flexibility and allows you to rank groups and carry totals forward dynamically.
Thank you.
Hi nagendranath,
You can use inscope() function to achieve this:-
Present Count =
SUM(Table[Present])
Present Custom Total =
VAR CurrentGroup =
SELECTEDVALUE(Table[Group])
VAR CurrentValue =
[Present Count]
VAR PreviousGroupsTotal =
CALCULATE(
[Present Count],
FILTER(
ALL(Table[Group]),
Table[GroupOrder] <
MAX(Table[GroupOrder])
)
)
RETURN
IF(
ISINSCOPE(Table[Nature of Work]),
-- Detail rows
CurrentValue,
-- Subtotal rows
CurrentValue + PreviousGroupsTotal
)
If this doesn't fix it, kindly share the DAX which you are using with sample data.
🌟 I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
🔗 Curious to explore more? [Discover here].
Let’s keep building smarter solutions together!