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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
tonmcg
Resolver II
Resolver II

Find n Number of Events Between Two Events

I have the following table, FactEvent. It details all the events an employee logs every day. I need to categorize each event as a work event, either TRUE or FALSE. A work event is any event that occurs between CLOCK IN and CLOCK OUT events, inlcusive of a CLOCK OUT event, except if these events occur between CLOCK IN and CLOCK OUT events for special TimeOff periods such as an Unpaid Lunch.

 

In the example below, I've incorrectly categorized the two events between a CLOCK IN and CLOCK OUT period as TRUE, the Badge to Breakroom event at 10:24 AM and the Badge to Arcade event at 10:34 AM, defined in the isWorkEvent column. I need these two events to be FALSE, as shown in the isWorkEvent2 column.

 

IndexDateIDDaily Clock In IndexDaily Clock Out IndexEmployeeDateTimeEventTimeOffisWorkEventisWorkEvent2
1120200110111John Smith1/10/2020 15:45CLOCK OUT TRUETRUE
1020200110111John Smith1/10/2020 15:30Last Task End TRUETRUE
920200110111John Smith1/10/2020 10:37CLOCK IN FALSEFALSE
820200110111John Smith1/10/2020 10:37CLOCK OUTUnpaid LunchFALSEFALSE
720200110111John Smith1/10/2020 10:34Badge to Arcade TRUEFALSE
620200110111John Smith1/10/2020 10:24Badge to Breakroom TRUEFALSE
520200110111John Smith1/10/2020 10:13CLOCK INUnpaid LunchFALSEFALSE
420200110111John Smith1/10/2020 10:13CLOCK OUT TRUETRUE
320200110111John Smith1/10/2020 10:04Badge to Breakroom TRUETRUE
220200110111John Smith1/10/2020 10:02First Task End TRUETRUE
120200110111John Smith1/10/2020 6:00CLOCK IN FALSEFALSE

 

Here are how I currently calculate isWorkEvent:

isWorkEvent = FactEvent[Index] >= FactEvent[Daily Clock In Index] && FactEvent[Index] <= FactEvent[Daily Clock Out Index] && ISBLANK( FactEvent[TimeOffID] ) && FactEvent[Event] <> "CLOCK IN"

 

How do I adjust isWorkEvent so that the two events between the 10:13 AM CLOCK IN and 10:37 AM CLOCK OUT events are FALSE?

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

Hi @tonmcg ,

 

You could refer to the following DAX:

isWorkEvent =
VAR a =
    CALCULATE (
        MAX ( FactEvent[Index] ),
        FILTER ( FactEvent, FactEvent[TimeOff] = "Unpaid Lunch" )
    )
VAR b =
    CALCULATE (
        MIN ( FactEvent[Index] ),
        FILTER ( FactEvent, FactEvent[TimeOff] = "Unpaid Lunch" )
    )
RETURN
    ( FactEvent[Index] >= FactEvent[Daily Clock In Index] )
    && ( FactEvent[Index] <= FactEvent[Daily Clock Out Index] )
    && ( FactEvent[TimeOff] = BLANK () )
    && ( FactEvent[Event] <> "CLOCK IN" )
    && OR ( FactEvent[Index] > a, FactEvent[Index] < b )

Here is the result.

2-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @tonmcg ,

 

You could refer to the following DAX:

isWorkEvent =
VAR a =
    CALCULATE (
        MAX ( FactEvent[Index] ),
        FILTER ( FactEvent, FactEvent[TimeOff] = "Unpaid Lunch" )
    )
VAR b =
    CALCULATE (
        MIN ( FactEvent[Index] ),
        FILTER ( FactEvent, FactEvent[TimeOff] = "Unpaid Lunch" )
    )
RETURN
    ( FactEvent[Index] >= FactEvent[Daily Clock In Index] )
    && ( FactEvent[Index] <= FactEvent[Daily Clock Out Index] )
    && ( FactEvent[TimeOff] = BLANK () )
    && ( FactEvent[Event] <> "CLOCK IN" )
    && OR ( FactEvent[Index] > a, FactEvent[Index] < b )

Here is the result.

2-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Greg_Deckler
Super User
Super User

Seems like you would just check the TimeOff value of the MAX CLOCK OUT event < current date/time and make sure the date/time is less than the next CLOCK IN even. If the TimeOff of the MAX CLOCK OUT event < current data/time of row is Unpaid lunch and there is no CLOCK IN event between that time and the current date/time. FALSE. 

 

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.