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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
bree_carter
New Member

calculate % based on multiple criteria

Hi,

I have data which shows shift hours, but I need to convert that to a shift quantity (or percentage of the shift on that day for that person). The issue I have is when there are 2 shift types on one day (ie: they might attend work and then leave part way through), so I need to show 0.# worked and 0.# unplanned leave. 

 

Columns A-D are what comes from a report.

Columns E & F are how I would do it in excel. If anyone can tell me how to do it in Power BI it would be greatly appreciated. 

 

Thanks in Advance. 🙂

 

bree_carter_0-1706320752586.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @bree_carter 

Please try this:

With your data, I create a calcualte column:

Calculated Shift = 
VAR _sumHours = CALCULATE(
                    SUM('Table'[Hours]),
                    FILTER('Table',
                        'Table'[Date]=EARLIER('Table'[Date])
                        &&
                        'Table'[Employee Id]=EARLIER('Table'[Employee Id])
                        )
                    )
//Get the sum of the Hours separately
RETURN 'Table'[Hours]/_sumHours

Select the Column(Calculated Shift) > Column tools > Change the Display the values in this column with commas as a thousand separator to 2

vzhengdxumsft_1-1706494072588.png

 

The result is as follow:

vzhengdxumsft_0-1706494041363.png

 

Best Regards,

Zhengdong Xu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @bree_carter 

Please try this:

With your data, I create a calcualte column:

Calculated Shift = 
VAR _sumHours = CALCULATE(
                    SUM('Table'[Hours]),
                    FILTER('Table',
                        'Table'[Date]=EARLIER('Table'[Date])
                        &&
                        'Table'[Employee Id]=EARLIER('Table'[Employee Id])
                        )
                    )
//Get the sum of the Hours separately
RETURN 'Table'[Hours]/_sumHours

Select the Column(Calculated Shift) > Column tools > Change the Display the values in this column with commas as a thousand separator to 2

vzhengdxumsft_1-1706494072588.png

 

The result is as follow:

vzhengdxumsft_0-1706494041363.png

 

Best Regards,

Zhengdong Xu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

This is PERFECT! Thank you so much. I really appreciate your time and help.

bree_carter
New Member

Thanks and apologies.

 

I have a payroll extract that shows hours per person per day. A person may have more than one type of entry for a day (shown in the yellow highlight above). IE: in one day, a person may have some worked hours and some paid leave hours.

 

I need to convert this information:

  • CURRENTLY:  hours, per person, per day, per worked shift or leave type
  • REQUIRE: calculated shift (Decimal format (to 2 decimal places)), per person, per day, per worked shift or leave type 

 

What I am trying to obtain is in column E in the above image.

An example would be: on 01/01/24, EMP001 worked 0.7 of a shift and had 0.3 of a shift as LWOP -Planned.

 

The headings are as per the report that comes out of the system.

Data is below. Thanks for your time. 🙂

 

Employee IdDateHoursTime Off NameCalculated Shift
EMP0011/01/20248Worked Shift 
EMP0011/01/20244LWOP - Planned 
EMP0012/01/202412Planned Annual Leave 
EMP0013/01/202412Worked Shift 
EMP0014/01/202412Worked Shift 
EMP0015/01/20245Personal Leave - Unplanned 
EMP0015/01/20245LWOP - Unplanned 
EMP0016/01/202412Worked Shift 
EMP0021/01/202410Worked Shift 
EMP0022/01/202410Worked Shift 
EMP0023/01/202410Planned Annual Leave 
EMP0024/01/202412Worked Shift 
EMP0025/01/202412Personal Leave - Unplanned 
EMP0026/01/20247Worked Shift 
EMP0026/01/20244LWOP - Unplanned 
speedramps
Community Champion
Community Champion

We want to help you but your description is too vaugue. Please write it again clearly.

We are Power BI expets but we dont know what you want your reports to do.

Provide example input data as table text (not a screen print) so we can import the data to build a solution for you.

Remove any unneeded columns which may cause confussion.

Rename columns to user friendly names.
Also provide the example desired output, with a clear description of the process flow.

Show step-by-step calulations.  

Take time and care to use the same table and field names in the input, output and description so we can understand your problem and help you.
Try keep it simple and ask one question per ticket.
You will get a quick response if you put time, care and effort into writing clear problem descriptions.
Remember you are gerrting free expert help, so please put lots of proper effort to asking questions and providing example.

Vaugue descriptions can waste your time and ourtime.

Look foward to helping you when the above information is forthcoming

We want to help you but your description is too vaugue. Please write it again clearly.

We are Power BI expets but we dont know your jargon like LWOP or what you want your reports to do!

Please ask a colleagueto manager to read your question, and help you write it for an external reader.

 

Why does 01/01/24, EMP001 = 0.7and  0.3 ???
Provide a clear step-by-step description of the process flow.

Show step-by-step calulations.  

Take time and care to use the same table and field names in the input, output and description so we can understand your problem and help you. T

Try include all the details in one post, so we dont have to scrool up and down to try fathom wahat you want.
Try keep it concise and simple and ask one question per ticket.
You will get a quick response if you put time, care and effort into writing clear problem descriptions.
Remember you are gerrting free expert help, so please put lots of proper effort to asking questions and providing example.

Vaugue descriptions can waste your time and ourtime.

Look foward to helping you when the above information is forthcoming

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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