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
sabry_303
Frequent Visitor

Calculate a measure by two categories

Hey Gurus,

 

I have the below table, and I  would like to create a measure to calculate % hours spent on each category per person.

 

So Jade will be 33% (1/3) in Category A ... etc... any ideas?

 

CategoryHoursName
A1Jade
A5Adam
B4Adam
B1Adam
D2Jade
1 ACCEPTED SOLUTION
TonyZhou1980
Resolver I
Resolver I

Hi Sabry,

 

Please try below measures, and make a visual as below,

% of hours per name =
var _name = max(Data[Name])
var _category = max(Data[Category])
var _currenthours =
    calculate(
        sum(Data[Hours]),
        Data[Category]=_category
    )
var _hours =
    calculate(
        sum(Data[Hours]),
        Data[Name]=_name,
        all()
    )
return
    if(
        ISINSCOPE(Data[Category]),
        divide(_currenthours,_hours),
        blank()
    )
 
TonyZhou1980_0-1674273719395.png

Regards

Tony

   

View solution in original post

5 REPLIES 5
TonyZhou1980
Resolver I
Resolver I

Hi Sabry,

 

Please try below measures, and make a visual as below,

% of hours per name =
var _name = max(Data[Name])
var _category = max(Data[Category])
var _currenthours =
    calculate(
        sum(Data[Hours]),
        Data[Category]=_category
    )
var _hours =
    calculate(
        sum(Data[Hours]),
        Data[Name]=_name,
        all()
    )
return
    if(
        ISINSCOPE(Data[Category]),
        divide(_currenthours,_hours),
        blank()
    )
 
TonyZhou1980_0-1674273719395.png

Regards

Tony

   

Thanks Tony a million, How to exclude ColumnX="Y" from sum of hours?

Hi Sabry,

 

I do not quite follow you question "How to exclude ColumnX="Y" from sum of hours", please explain a bit more^-^.

 

Regards

Tony

Ashish_Mathur
Super User
Super User

Hi,

How is Jade 1/3 for category A????? 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
FreemanZ
Super User
Super User

hi @sabry_303 

try to plot a table visual with name, category, and a measure like this:

Ratio =
VAR _name = MAX(TableName[Name])
VAR _hours = SUM(TableName[Hours])
VAR _hoursall =
SUMX(
   FILTER(
       ALL(TableName), 
       TableName[Name]=_name
   ),  
TableName[Hours])
)
RETURN
DIVIDE(_hours, _hoursall)

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.