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
Joris_NL
Helper I
Helper I

Need percentage of total after SUMX - SUMMARIZE

Hi,

 

I'm struggling for hours now. 

I have data like this:

 

Person  ContractHours  SomeRecordNotRelevant  
12015
12016
23017
23018
31019

 

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
AlexisOlson
Super User
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 )

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
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 )

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. 

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.