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

Calculate %Overtime worked with SLICER

Hello,

I need to calculate %OT worked and have that number be dynamic (changing around slicer selection).

 

I know I could use =SUM(SCHED_OT_HRS) + SUM( UNSCHED_OT_HRS) / SUM TOTAL HRS but this gives me a fixed value over the entire dataset that doesn't dynamically change with a slicer.

 

Thank you in advance for any help.

 

WORK_DATEREG_HRSSCHED_OT_HRSUNSCHED_OT_HRSTOTAL_HRS
1/1/2019120012
1/1/2019120012
1/1/2019120012
1/1/2019100010
1/1/20190000
1/1/2019240024
1/1/2019240024
1/1/2019240024
1/1/20190000
1/1/2019240024
1/1/2019360036
1/1/2019240024
1/1/2019360036
1/1/2019120012
1/1/2019001212
1/1/20198008
1/1/2019360036
1/1/2019120012
1/1/2019160016
1/1/2019100010
1/1/20190000
1/1/2019120012
1/1/2019160016
1/1/20190000
1/1/201914400144
7 REPLIES 7
v-yiruan-msft
Community Support
Community Support

Hi @leejoel ,

Which field will be used on slicer options? Could you please check if the following screen shot is your expected result? If yes, please  create slicer with the field "WORK_DATE" first, then create a measure with below formula:

 

%OT = 
DIVIDE (
    SUM ( 'Labor_Hours_Team_Summary_2020-0'[SCHED_OT_HRS] )
        + SUM ( 'Labor_Hours_Team_Summary_2020-0'[UNSCHED_OT_HRS] ),
    SUM ( 'Labor_Hours_Team_Summary_2020-0'[TOTAL_HRS] )
)

 

slicer.JPGIf the above info is not applicable for your scenario,  please provide more detail about your requirement. Thank you.

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

This is the correct measure:

%OT Worked =
DIVIDE(
	sum( T[sched_ot_hrs] ) + sum( T[unsched_ot_hrs] ),
	sum( T[total_hrs] )
)

and if your data looks like what you've posted, then since all the dates are the same, the measure will also be the same for any selection of dates if 1/1/2019 is among them. If not, the measure results in BLANK.

 

Best

D

This did the trick. Thank you very much!

AllisonKennedy
Super User
Super User

@leejoel  What slicers does it need to change with? Does your example use a MEASURE or COLUMN?

 

Try 

MEAURE = AVERAGEX(WorkTable, (WorkTable[Sch_OT_HRS]+ WorkTable[UNSCHED_OT_HRS]) / WorkTable[TOTAL_HRS])

I suggested AVERAGEX instead of SUMX since you're working with %, but if you give more info we can help better.

 

Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 

 

If you found this post helpful, please give Kudos.

I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 

https://sites.google.com/site/allisonkennedycv


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedyThanks for the reply but that seems to return 'NaN' on every row. My example is currently using COLUMN but I'm open to any suggestions.

 

The way the line items are broken out sometimes the calculation reverses (OT>REG HR) whereas other times it's normal (REG HR>OT). Could this be why I am getting NaN with your suggestion?

You need to do that suggestion as a MEASURE, the X part in the AVERAGEX creates a virtual calculated column for you. 

 

the NaN is because total hours is sometimes zero, so put that in a DIVIDE function: 

 

MEASURE = AVERAGEX(WorkTable, DIVIDE(WorkTable[Sch_OT_HRS]+ WorkTable[UNSCHED_OT_HRS]) , WorkTable[TOTAL_HRS]),0))

 

Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 

 

If you found this post helpful, please give Kudos.

I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 

https://sites.google.com/site/allisonkennedycv


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

What am I missing?

Measure 2 = AVERAGEX('Labor_Hours_Team_Summary_2020-0', DIVIDE('Labor_Hours_Team_Summary_2020-0'[SCHED_OT_HRS] + 'Labor_Hours_Team_Summary_2020-0'[UNSCHED_OT_HRS]) , 'Labor_Hours_Team_Summary_2020-0'[TOTAL_HRS]),0))
 
It seems to error toward the end.

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.