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
android1
Post Patron
Post Patron

Using IF to see if an appointment was early or late

Hi,

 

I am using the following calculated column which tells me if an appointment was early or late -> Punctuality = IF (OTIF[DutyTimeFrom]<OTIF[TimeFrom]-1/24*.25,"Early",IF (OTIF[DutyTimeFrom]>OTIF[TimeFrom]+1/24*.25,"Late"

 

An appointment is early if it is 15mins before start time so if appointment time is 17:00 then you are early if you arrive before 16:45.

Appointment is late if it is 15 mins after start time so you are late if you arrive after 17:15.

 

I now need to only show early and late if you are at most 15 mins early or late. In the example above, early would be before 16:45 but not before 16:30 ie between 16:45 and 16:30. Late would be between 17:15 and 17:30.

3 ACCEPTED SOLUTIONS
SamLester
Employee
Employee

You can use the AND function to enforce the two constraints.

 

Ex: 

IF (AND(OTIF[DutyTimeFrom]<otif[timefrom]-1/24*.25, OTIF[DutyTimeFrom] > otif[timeFrom] - 1/24 * .5),"early", "not early enough")

 

http://social.technet.microsoft.com/wiki/contents/articles/682.power-bi-dax-logical-functions.aspx

 

AND Checks whether both arguments are TRUE, and returns TRUE if both arguments are TRUE. Otherwise returns FALSE.

Returns true or false depending on the combination of values that you test.

Syntax

AND(<Logical1>, <logical2>)

 

Thanks,
Sam Lester (MSFT)

 

View solution in original post

You can string together longer AND statements using the && operator. The AND function can only check two conditions unless you nest sub-ANDs.

 

IF (

OTIF[DutyTimeFrom]<otif[timefrom]-1/24*.25 &&

OTIF[DutyTimeFrom] > otif[timeFrom] - 1/24 * .5,

"early",

"not early enough")

 

...will behave the same way, and if you have some third condition you can just tack on another && <insert condition here>.





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

Proud to be a Super User!




View solution in original post

Sean
Community Champion
Community Champion

@android1 This should do it Smiley Happy

 

Punctuality =
SWITCH (
    TRUE (),
    OTIF[DutyTimeFrom] < OTIF[TimeFrom] - 1/24*0.25 && OTIF[DutyTimeFrom] >= OTIF[TimeFrom] - 1/24*0.5, "Early",
    OTIF[DutyTimeFrom] > OTIF[TimeFrom] + 1/24*0.25 && OTIF[DutyTimeFrom] <= OTIF[TimeFrom] + 1/24*0.5, "Late",
    "Don't Care!"
)

 

View solution in original post

4 REPLIES 4
SamLester
Employee
Employee

You can use the AND function to enforce the two constraints.

 

Ex: 

IF (AND(OTIF[DutyTimeFrom]<otif[timefrom]-1/24*.25, OTIF[DutyTimeFrom] > otif[timeFrom] - 1/24 * .5),"early", "not early enough")

 

http://social.technet.microsoft.com/wiki/contents/articles/682.power-bi-dax-logical-functions.aspx

 

AND Checks whether both arguments are TRUE, and returns TRUE if both arguments are TRUE. Otherwise returns FALSE.

Returns true or false depending on the combination of values that you test.

Syntax

AND(<Logical1>, <logical2>)

 

Thanks,
Sam Lester (MSFT)

 

You can string together longer AND statements using the && operator. The AND function can only check two conditions unless you nest sub-ANDs.

 

IF (

OTIF[DutyTimeFrom]<otif[timefrom]-1/24*.25 &&

OTIF[DutyTimeFrom] > otif[timeFrom] - 1/24 * .5,

"early",

"not early enough")

 

...will behave the same way, and if you have some third condition you can just tack on another && <insert condition here>.





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

Proud to be a Super User!




Sean
Community Champion
Community Champion

@android1 This should do it Smiley Happy

 

Punctuality =
SWITCH (
    TRUE (),
    OTIF[DutyTimeFrom] < OTIF[TimeFrom] - 1/24*0.25 && OTIF[DutyTimeFrom] >= OTIF[TimeFrom] - 1/24*0.5, "Early",
    OTIF[DutyTimeFrom] > OTIF[TimeFrom] + 1/24*0.25 && OTIF[DutyTimeFrom] <= OTIF[TimeFrom] + 1/24*0.5, "Late",
    "Don't Care!"
)

 

Thanks everyone. All these work perfectly.

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.