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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
leonardosilva
Regular Visitor

How to calculate duration between events in a events table

Hi there,

 

I have a database that contains a list of users events in my App, basically where and when they click. The collumns I have are User ID, event type (as login, product selection, cart, payment options and confirmation) and time (in timestamp). I wanna know how many time users spend in each action using this data.

 

This can be done by creating a collumn that contains the time diference between two consectutive events of the same user (the first event can be ignored), but I coudn´t find a way to realize this. I have also tried to use the function EARLIER, but since my database is 20000 rows long, it keeps loading for minutes until I give up on it.

 

Can Power BI do this?

 

4 REPLIES 4
vivran22
Community Champion
Community Champion

Hello @leonardosilva ,

 

Can you please share a sample data set along with the expected outcome?

 

Cheers!
Vivek

https://www.vivran.in/
Connect on LinkedIn

 

This is the desired outcome and an example I did with the EARLIER function:

 

Exemplo.png

 

When I applied this to the original database, it took 26 minutes to display a mensage saying I don´t have enough memory (I have 8GB) to make the process.

 

Hi @leonardosilva ,

 

Please try this one.

Column = 
VAR t = 'Plan1'[timestamp]
VAR last =
    CALCULATE (
        MAX ( 'Plan1'[timestamp] ),
        FILTER (
            'Plan1',
            'Plan1'[timestamp] < t
                && 'Plan1'[userid] = EARLIER ( 'Plan1'[userid] )
        )
    )
RETURN
    t - last

Capture.PNG

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi, @v-frfei-msft 

 

I´ve tried this solution in my database but it also took 35 minutes and again displayed a mensage saying I don´t have enought memory. This is probably happening because my database is 20000+ rows long. Do you know another way to solve this using less memory?

 

 

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
Top Kudoed Authors