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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
Community Champion
Community Champion

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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.