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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
805
Frequent Visitor

Count of events with time constraints

Hi Community, 

 

I need some help with building a calculated column.  

Here's the scenario:

if 4 records/rows (events) happened to the same entity within 4 hours I need to flag those events.   

example data: 

 

Entity | Event | Desired Flag

123 | 3/17/2020 2:04:00 AM | No 

123 | 3/17/2020 3:20:00 AM | No

456 | 3/17/2020 9:00:00 AM | Yes

456 | 3/17/2020 9:40:00 AM | Yes

456 | 3/17/2020 10:30:00 AM | Yes

456 | 3/17/2020 11:10:00 AM | Yes

456 | 3/20/2020 12:00:00 PM | No

 

Thanks. 

 

3 REPLIES 3
AlB
Community Champion
Community Champion

@805 

Try this

Flag V2 = 
VAR eventsIn4hWindow_ =
    CALCULATETABLE (
        DISTINCT ( Table1[Event] ),
        ALLEXCEPT ( Table1, Table1[Entity] ),
        Table1[Event] >= (EARLIER ( Table1[Event] ) - ( 4 / 24 )),
        Table1[Event]<= (EARLIER ( Table1[Event] ) + ( 4 / 24 ))
    )
VAR checkT_ =
    FILTER (
        eventsIn4hWindow_,
        COUNTROWS (
            FILTER (
                eventsIn4hWindow_,
                Table1[Event] >= EARLIER ( Table1[Event] ) && Table1[Event]<= (EARLIER ( Table1[Event] ) + ( 4 / 24 ))
            )
        ) >=4
    )
RETURN
    IF ( ISEMPTY ( checkT_ ), "No", "Yes" )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

AlB
Community Champion
Community Champion

Hi @805 

You need to specify  bit more.

Are we looking at four events within the same day? CAn the number of events in one day be > 4?

What happens if there are more than 4 events than fall in the same four hour period?

What in a case like this? What would be the right flags?

456 | 3/17/2020 9:00:00 AM | Yes

456 | 3/17/2020 9:40:00 AM | Yes

456 | 3/17/2020 10:30:00 AM | Yes

456 | 3/17/2020 11:10:00 AM | Yes

456 | 3/17/2020 12:30:00 AM | Yes

456 | 3/17/2020 13:10:00 AM | Yes

456 | 3/17/2020 15:10:00 AM | Yes

456 | 3/17/2020 16:10:00 AM | Yes

456 | 3/17/2020 17:05:00 AM | Yes

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

805
Frequent Visitor

Hey @AIB  Looking to flag events that occur in any 4 hour period so it's possible they could cross into the following day (11PM-3 AM.) The number of events can be greater than 4 in a 4 hour period.  

What happens if there are more than 4 events than fall in the same four hour period? - All events for that entity need to be flagged.  For context this is related to MTP (massive transfusion protocol) related to blood transfusions. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.