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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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