cancel
Showing results 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.

Helper I

## Need percentage of total after SUMX - SUMMARIZE

Hi,

I'm struggling for hours now.

I have data like this:

 Person ContractHours SomeRecordNotRelevant 1 20 15 1 20 16 2 30 17 2 30 18 3 10 19

I need an answer like this:

Person 1 who has 20 hours = 33% (20 out of 20+30+10 total hours)
Person 2  with 30 hours = 50%

Person 3 = 16,7%

So what I tried is a measure like this:

VAR HoursOverview =
SUMMARIZE('Table' ; 'Table'[Person] ; "Hours" ; MAX ( 'Table'[ContractHours] ))

VAR HoursPerPerson =
SUMX ( HoursOverview ; [Hours] )

VAR GrandTotalHours =
???

RETURN
DIVIDE ( HoursPerPerson ; GrandTotalHours ; 0 )

Which makes me clueless, because ALL or FILTER functions don't work on the VAR tables, so I can't get a Grand Total. Please help!
1 ACCEPTED SOLUTION
Super User

Try using ALL or ALLSELECTED for calculating the grand total hours.

``````VAR AllHoursOverview =
SUMMARIZE (
ALLSELECTED ( 'Table' );
'Table'[Person];
"Hours"; MAX ( 'Table'[ContractHours] )
)
VAR HoursOverview =
SUMMARIZE ( 'Table'; 'Table'[Person]; "Hours"; MAX ( 'Table'[ContractHours] ) )
VAR HoursPerPerson =
SUMX ( HoursOverview; [Hours] )
VAR GrandTotalHours =
SUMX ( AllHoursOverview; [Hours] )
RETURN
DIVIDE ( HoursPerPerson; GrandTotalHours; 0 )``````
2 REPLIES 2
Super User

Try using ALL or ALLSELECTED for calculating the grand total hours.

``````VAR AllHoursOverview =
SUMMARIZE (
ALLSELECTED ( 'Table' );
'Table'[Person];
"Hours"; MAX ( 'Table'[ContractHours] )
)
VAR HoursOverview =
SUMMARIZE ( 'Table'; 'Table'[Person]; "Hours"; MAX ( 'Table'[ContractHours] ) )
VAR HoursPerPerson =
SUMX ( HoursOverview; [Hours] )
VAR GrandTotalHours =
SUMX ( AllHoursOverview; [Hours] )
RETURN
DIVIDE ( HoursPerPerson; GrandTotalHours; 0 )``````
Helper I

Thanks, it works!

I doubt my 4 variables are a clean solution, but I don't know any better atm and it works for now.

Announcements

#### 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

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors