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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
czaldumbide
Helper I
Helper I

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]))

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors