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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jvandyck
Helper IV
Helper IV

time elapsed across multiple records

Hi

 

Looking for help on this challenge. I have a tabel with logon/off events per employee and per ip adress. Based on this information I want to get the total active time per day per user, across ip addresses.

 

An example table looks like this:

 

 EmployeeDate IPStartEndDuration
A7/06/201810.101.11708:00:00.000000016:00:00.0000000480
A7/06/201810.101.117.5413:00:00.000000017:00:00.0000000240
A7/06/201810.101.201.17819:00:00.000000020:00:00.000000060
A7/06/201810.101.201.13619:30:00.000000020:30:00.000000060

 

As you see the duration needs to be calculated across the different records and in between records there can be wholes as well as overlap. The total time to be calculated in this example would be 10.5 hours, and not just the sum of duration.

3 REPLIES 3
Stachu
Community Champion
Community Champion

that's an interesting one, I have solution, but I fear performance may be terrible with bigger dataset

the concept is following
1) I created a table of time ticks (every one minute in my case, you may need to adjust it to get desired precision/performace)

Time
00:00:00
00:01:00
00:02:00
00:03:00
00:04:00

...
up to 23:59:00

2) generate a cartesian product of that table with the one that you provided
3) check if the time ticks are between Start/End,
4) filter only those ticks

5) group by to get unique logged in ticks
6) count the ticks to and divide by 60 to get the result in hours
Final measure (covers steps 2-6)

LoggedInTime :=
VAR TimePerUser =
    GENERATE ( 'Time', 'Table' )
VAR TotalTimeSummary =
    ADDCOLUMNS (
        TimePerUser,
        "TimeFlag", 'Time'[Time] >= [Start]
            && 'Time'[Time] < [End]
    )
VAR OnlyLoggedTime =
    FILTER ( TotalTimeSummary, [TimeFlag] = TRUE )
VAR UniqueTimeTicks =
    GROUPBY ( OnlyLoggedTime, 'Time'[Time] )
RETURN
    COUNTROWS ( UniqueTimeTicks ) / 60


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Creative! But with 1500 employees and multiple lines per user, this will not work i think

Stachu
Community Champion
Community Champion

well, it already works for multiple users and multiple lines per user, the question is performance
for the example you posted it gives 10,5, adding other users works as well

EDIT - unless your point is about aggregating times of different users - then you need to add user in GroupBy



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors