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

How to count all events happening 24hrs from an event?

I have a list of events with their begin and end times like so:

 

Ref NumStartEnd
1141/1/2023 0:051/1/2023 6:29
8911/1/2023 19:061/1/2023  19:53
4161/1/2023 22:061/1/2023  22:46
3101/1/2023 23:101/1/2023 23:02
2001/2/2023 0:141/2/2023 3:07
9261/2/2023 3:191/2/2023 3:36
3981/2/2023 6:191/2/2023 6:41
6081/3/2023 10:251/3/2023 10:18
401/3/2023 13:271/3/2023 13:08
4031/3/2023  16:331/3/2023 16:35
6681/3/2023 20:091/3/2023 20:15
8541/4/2023 1:091/4/2023 2:01
2501/4/2023 5:171/4/2023 5:12

 

I want to count all the events that are within 24hrs after the event time like so:

 

Ref NumStartEndCount
1141/1/2023 0:051/1/2023 6:294
8911/1/2023 19:061/1/2023  19:536
4161/1/2023 22:061/1/2023  22:465
3101/1/2023 23:101/1/2023 23:024
2001/2/2023 0:141/2/2023 3:073
9261/2/2023 3:191/2/2023 3:362
3981/2/2023 6:191/2/2023 6:411
6081/3/2023 10:251/3/2023 10:185
401/3/2023 13:271/3/2023 13:084
4031/3/2023  16:331/3/2023 16:353
6681/3/2023 20:091/3/2023 20:153
8541/4/2023 1:091/4/2023 2:012
2501/4/2023 5:171/4/2023 5:121

 

 

I was able to do this in excel using this function:

 

=SUMPRODUCT(--($E$6:$E$18<(E6+1)),--($E$6:$E$18>E6))+1

 

where E is the Start column. But I cannot figure how to do this in PowerBI.

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Gerbil 

 

You can try the following methods.
Column:

Start+24h = [Start]+1
Count = 
CALCULATE ( COUNT ( 'Table'[Ref Num] ),
    FILTER ( ALL ( 'Table' ),
        [Start] >= EARLIER ( 'Table'[Start] )
            && [Start] <= EARLIER ( 'Table'[Start+24h] ) ) )

vzhangti_0-1682045009664.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-zhangti
Community Support
Community Support

Hi, @Gerbil 

 

You can try the following methods.
Column:

Start+24h = [Start]+1
Count = 
CALCULATE ( COUNT ( 'Table'[Ref Num] ),
    FILTER ( ALL ( 'Table' ),
        [Start] >= EARLIER ( 'Table'[Start] )
            && [Start] <= EARLIER ( 'Table'[Start+24h] ) ) )

vzhangti_0-1682045009664.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.