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
clewis
Helper I
Helper I

Working with timestamp data - looking at average duration. Please help!

Hi everyone!

 

I have a table of network access data.  I have IP addresses and then the date and time of when the device get on and off the network throughout the day.  There are multiple associations for each device everyday due to different AP devices. 

 

I want to look at the IP address on a given day, and get the Max sign off time (example Sept 8th 5:15 PM) and subtract the min sign on time (example: Sept 8th 8:03 AM) to understand approximately how long that person was at the office on a given day.  I want to plot this daily average # of hours over time.  Can you help with this one?

 

Below, is a simple example.  Users 1a and 2b each have two network associations on 9/8/2021.  I want to calculate their durations on that day by subtracting their earliest timestamp from their latest and take the average for all devices.

 

 

Log TimestampIP ADDRESSVisit Start TimestampVisit End Timestamp
2021-09-08 00:18:42UTC1a2021-09-08 00:14:41UTC2021-09-08 00:17:39UTC
2021-09-08 00:55:21UTC2b2021-09-08 00:34:19UTC2021-09-08 00:44:28UTC
2021-09-08 00:18:42UTC1a2021-09-08 02:14:41UTC2021-09-08 02:17:39UTC
2021-09-08 00:55:21UTC2b2021-09-08 00:44:28UTC2021-09-08 00:54:28UTC
2021-09-07 11:18:44UTC3c2021-09-07 11:17:26UTC2021-09-07 14:18:36UTC
2021-09-07 11:24:10UTC1a2021-09-07 11:24:18UTC2021-09-07 15:24:04UTC

 

9/8/2021 average duration = 1.1 hours

9/7/2021 average duration = 3.5 hours

13 REPLIES 13
v-luwang-msft
Community Support
Community Support

Hi @clewis ,

Could you pls share your pbix file ,and remove confidential data.

 

Best Regards

Lucien

Hi @v-luwang-msft were you able to access the file?

Hi @v-luwang-msft I've cleaned up the file and ready to share it.  How do i do that?  I dont see an attachment icon.

Hi @clewis ,

Share your link by a public link.

 

Best Regards

Lucien

v-luwang-msft
Community Support
Community Support

Hi @clewis ,

In my opinion, you can count the number of unduplicated IPs in the average duration.

In the sample ,the same measure(May have to be rounded up or down, depending on whether you need) with distincount Ip.

 

 

Best Regards

Lucien

Hi @v-luwang-msft 

 

1.  I dont think I understand how to do that.  Can you walk me through plotting the duration distribution in this format?

clewis_1-1632256419742.png

 

 

2. This formula is not calculating properly.  See below sample data for just Sept 20.  The formula is calculating the daily average to be 5.17 hours but it should be 3.81 hours.  The table below is calculating correctly for each individual IP address on a given day.  

clewis_0-1632256344292.png

 

 

v-luwang-msft
Community Support
Community Support

Hi  @clewis ,

Test below :

Create the data column:

DATE1 = FORMAT('Table'[Log Timestamp],"yyyymmdd")

vluwangmsft_0-1631694620391.png

 

Then create the below measure:

test = var datediff1=DATEDIFF(
CALCULATE (
        MIN ( 'Table'[Visit Start Timestamp] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[IP ADDRESS] = MAX ( 'Table'[IP ADDRESS] )
                && FORMAT ( 'Table'[Log Timestamp], "yyyymmdd" )
                    = FORMAT ( MAX ( 'Table'[Log Timestamp] ), "yyyymmdd" )
        )),CALCULATE (
    MAX ( 'Table'[Visit End Timestamp] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[IP ADDRESS] = MAX ( 'Table'[IP ADDRESS] )
            && FORMAT ( 'Table'[Log Timestamp], "yyyymmdd" )
                = FORMAT ( MAX ( 'Table'[Log Timestamp] ), "yyyymmdd" )
    )),
MINUTE)/60     return datediff1
Measure = AVERAGEX(FILTER(ALL('Table'),'Table'[DATE1]=MAX('Table'[DATE1])),[test])

Final output:

vluwangmsft_1-1631694713402.png

You could download my pbix file if you need.

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

   

 

goncalogeraldes
Super User
Super User

Hello there @clewis ! I hope I understood your question correctly. Try this:

 

 

Average =
var _min = MIN( Table[Start Timestamp] )
var _max = MAX( Table[End Timestamp] )
var _log = SELECTEDVALUE( Table[Log Timestamp] )

return
CALCULATE(
AVERAGEX( Table, _min + _max ),
Table[Log Timestamp] = _log
)

 

  If the CALCULATE() does not work try with an IF()!

 

Hope this answer solves your problem! If you need any additional help please tag me in your reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️ or give it a kudoe 👍
Thanks!

Best regards,
Gonçalo Geraldes

Hi Goncalo!

 

I need to find the difference between the last end timestamp and first start time stamp for each unique IP address each day. Then i need to take the average and plot the distribution of durations.  Do you have any ideas on how to do that?  It doesnt look like the above takes into consideration the different users.

 

Thank you!

Caiti

Helpful resources

Announcements
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!

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.

Top Solution Authors
Top Kudoed Authors