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

IF Statement Help

I need a little help with an IF statement as it's somewhat working but not fully.

 

The statement is this:

xMeasure = IF(Employee[Duration] >= 8, 1, Employee[Duration]/8)

 

What I'm trying to get to happen is that if an employee has worked 8 or more hours in a day, fill in xMeasure with a '1'.  Else, divide their time by 8 to get some decimal number (i.e. 6 hours / 8 hours would be 0.75).

 

This is almost all working in the sense that it's doing the math on the IF FALSE part of the statement.  But, if I have an employee that worked 9.25 hours, it fills in xMeasure with 1.16 vs. just a 1.

 

Data types all appear to be correct in that Employee[Duration] is a "Decimal Number" and xMeasure is a "Decimal Number."

 

Employee[Duration] is being calculated by: ( ( DATEDIFF ( Timecards[ActualStartTime], Timecard[ActualEndTime], SECOND ) ) /60 ) /60

4 REPLIES 4
kcantor
Community Champion
Community Champion

@jhudson1977 

Have you tried simply reversing the logic to remove any decimal issues that might be occuring?

xMeasure = IF(Employee[Duration] < 8,  Employee[Duration]/8, 1)

I would assume since you are calculating the hours that somewhere a calculation is continuing into decimal places that are hidden. 

 





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

Proud to be a Super User!




Based on this, I did go back to the start.  I decided to make a new calculated column that does nothing but takes the Employee[Duration] column and divides by 8.  Low and behold a discrepency developed.  Digging a bit further, I found that for every employee that simply clocks in followed by a clock out at the end of the day (meaning no break in between), the IF statement works fine.  However, for the employees that are following the rules (a discussion for another forum) and clocking in in the morning, clocking out at lunch, clocking in after lunch, and clocking out at the end of the day (so - two time entries per day), the formula wasn't working.

 

The way the two times were being aggregated was by simply removing the two columns.  So, I DO need to go back and look at that Employee[Duration] column formula and getting a little more specific on it.

 

I'll start another thread if I need help with that one. 

Thank you for the response.

 

I hadn't tried that, but I did as you suggested.  Interestingly enough, there was no change in any of the values.  So, that gives me a couple of clues.

I need to correct my original question/problem/statement.

 

This column isn't a measure but rather a new calculated column.  Not sure if that has any bearing on the result.

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.