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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.