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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
PowerBIFreak
Helper II
Helper II

New Column with IF STATEMENT

Hi Folks,

I have a table with some columns as below. The print screen below is a table from Power BI. This is perfect if I just want to see each employees' hours on a daily basis. However, I would like to calculate their over time hours. I want to add a column name OT and the formula if it's on Excel, it would be like this:

OT = If("Sum of Hours">8, "Sum of Hours" - 8, "No OT") 

Other words, the 1 to 3 rows with 8 hours, the "OT" column will show "No OT" for the 9 hours will show 1.

How do I do this on Power BI? Do I need to write DAX? or I can do the quick measure? Please help. Thank you.PowerBIFreak_0-1672871163244.png

This is the data source (Table)

PowerBIFreak_0-1672872507438.png

 

 

2 ACCEPTED SOLUTIONS

@PowerBIFreak 

is this what you want?

 

Column 2 = if('Table'[Column]="OT", CALCULATE(sum('Table'[Hours]),ALLEXCEPT('Table','Table'[Date],'Table'[Employee]))-8,0)

1.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

pls provide the sample data





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
ryan_mayu
Super User
Super User

@PowerBIFreak 

you can try this to create a column

 

Column = if(CALCULATE(sum('Table'[Hours]),ALLEXCEPT('Table','Table'[Date],'Table'[Employee]))>8,"OT","NOT OT")

1.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you very much, it works perfect. Now, I want to calculate how many OT hours for each employee. I've tried something like this to create a new column but of course it didn't work.

 

Drivers' OT = IF('Table'[column]=OT, (SUM('Table'[Hours],ALLEXCEPT('Table','Table'[Date],'Table'[Employee]))-8, 0)
 
For example, Paul has 1 hour OT. How I interpret this is if the Column said OT, then I will add up his total hours for him than minus 8 because anything that is exceed 8 hours is OT; otherwise, 0. So, on my new column that named "Drivers' OT" I will have 1 for Paul. Would you mind to help me with the Dax I had? 
I appreciate your time. 

@PowerBIFreak 

is this what you want?

 

Column 2 = if('Table'[Column]="OT", CALCULATE(sum('Table'[Hours]),ALLEXCEPT('Table','Table'[Date],'Table'[Employee]))-8,0)

1.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Sorry for the delay. Yours look exactly what I need but when I applied the code to mine, the calculation is totally off. I don't know what happened. Thank you so much for your time.😊🙏

 

PowerBIFreak_0-1673365445052.png

 

pls provide the sample data





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Good morning Ryan. Thank you very much for following up. I think I don't need further assistance because the report that I downloaded did indicate the OT hours for each employee outside of the normal hours. That way, I can just filter them out when I did the report. Thank you again for your help. Have a great day.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.