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

If condition between two times

I am trying to use an if statement to determine type of wastage created between two tim frames.

 

The idea is that between 14:30 and midnight the wastage is labelled as "End of Day Wastage" and the rest of the time it is labelled as just "Wastage".

 

The date and time column is formatted like this "DDMMYYYY HHMMSS"

 

This is the formula I am using but it doesnt work. It displays everything as "Wastage".

Wastage Type = IF(AND(Time(Hour(Wastage[Transaction Date]),minute(Wastage[Transaction Date]),SECOND(Wastage[Transaction Date])) > Time(16,30,00), Time(Hour(Wastage[Transaction Date]),minute(Wastage[Transaction Date]),SECOND(Wastage[Transaction Date])) <= Time(00,00,00)), "End of Day Wastage", "Wastage")

 

I am guessing it is probably something wrong with my logic but just can't see it.

 

Can anyone help, please?

1 ACCEPTED SOLUTION
WillemUK
Frequent Visitor

No worries i solved it.

 

The automatic cutoff time was 59:59:59 so at 00:00:00 the calculation returned back to "Wasted".

 

I removed the AND() and Time(Hour(Wastage[Transaction Date]),minute(Wastage[Transaction Date]),SECOND(Wastage[Transaction Date])) <= Time(00,00,00)) from the formula.

 

Here is the working code:

Wastage Type = IF(Time(Hour(Wastage[Transaction Date]),minute(Wastage[Transaction Date]),SECOND(Wastage[Transaction Date])) > Time(16,30,00), "End of Day Wastage", "Wastage")

View solution in original post

2 REPLIES 2
WillemUK
Frequent Visitor

No worries i solved it.

 

The automatic cutoff time was 59:59:59 so at 00:00:00 the calculation returned back to "Wasted".

 

I removed the AND() and Time(Hour(Wastage[Transaction Date]),minute(Wastage[Transaction Date]),SECOND(Wastage[Transaction Date])) <= Time(00,00,00)) from the formula.

 

Here is the working code:

Wastage Type = IF(Time(Hour(Wastage[Transaction Date]),minute(Wastage[Transaction Date]),SECOND(Wastage[Transaction Date])) > Time(16,30,00), "End of Day Wastage", "Wastage")

Hello! 

 

I also want to have a formula for below condition:

If time is within 06:01 AM to 20:30PM, it will display as "Beyond the shift". Can you help me?

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.