Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
czaldumbide
Helper II
Helper II

Percentage over subtotal in hierarchical matrix

Hi Everyone,

 

I have the following hierarchical matrix with all my rows expanded. I want to calculate the % based on the respective total for In/Out of that account as you will see on the example below. 

 

As you can see for the first row I have an amount of 120, which if divided by Total In for that account will be 120/450 = 26.6%. The same goes with the subtotal for Type. They should also be calcualted based on the total for In/Out (ex: 370/450 = 82.2%)

 

In terms of the data, all fields in this matrix come from a single table called Transactions. 

 

Here is an example to guide you. My matrix obviously has several accounts, so I want the percentage calculated based on the totals for each account. 

 

Any suggestions on how to write a measure that could calculate what I want would be appreciated. Thank you

 

NameAccountIn/OutTypeCounterpartyCountryAmountVolume%
A123InWiresMarioUSA120526.6%
---WiresJasonJAPAN2501055.5%
---Total Wires - -3701582.2%
---CashSarahUSA45210%
---CashMarioMEXICO3517.7%
---Total Cash - -80317.7%
--Total In - -45018100%
--OutWiresKyleCANADA400842.1%
---WiresSarahBOLIVIA350236.8%
---Total Wires - -7501078.9%
---ChecksCamilaUSA200521.1%
---Total Checks - -200521.1%
--Total Out - - -95015100%
5 REPLIES 5
Anonymous
Not applicable

Try this:

Amount % = 
var __currentAmount = [Total Amount]
var __inoutTotalAmount =
	CALCULATE(
		[Total Amount],
		KEEPFILTERS(		
			CROSSJOIN( 
				values( Transactions[Name] ),
				values( Transactions[Account] ), 
				values( Transactions[In/Out] )
			)
		),
		ALLSELECTED( Transactions )
	)
var __result =
	DIVIDE(
		__currentAmount,
		__inoutTotalAmount
	)
return
	__result

 

Best

D

 

amitchandak
Super User
Super User

@czaldumbide ,

see if something like this

divide([Amount], calculate([Amount],allexcept(Table,Table[Name],Table[Account],Table[In/Out]))
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak and @lbendlin 

 

Your suggestions are not giving me the correct numbers yet. The percentages are a lot smaller than they should so I'm assuming its not dividing bu the total In/out for that particular account. Let me know if you have other suggestions. 

 

My measure looks like this:

The part in red is not working proporly yet, but the part in blue which applies to all subtotals is. 

 

% over in/out = IF( ISFILTERED(TRANSACTIONS[Counterparty]),

DIVIDE(SUM(TRANSACTIONS[Amount]), CALCULATE(SUM(TRANSACTIONS[Amount]),

ALLEXCEPT(TRANSACTIONS, TRANSACTIONS[Name],TRANSACTIONS[Account], TRANSACTIONS[In/Out])), DIVIDE(SUM(TRANSACTIONS[Amount]), CALCULATE(SUM(TRANSACTIONS[Amount]), ALLSELECTED(TRANSACTIONS[Type]))))

 

 

Any suggestions on how to do this? I still haven't figured out a solution by myself.

 

Thanks!

lbendlin
Super User
Super User

Use ALLEXCEPT to take [In/Out] and its parents out of the equation.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.