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
Anonymous
Not applicable

How can I measure the time spent on each state

 

Hi, 

 

I have the following data - each ID spends some time on different states that can reoccur over time. I need to calculate the time overall time spent on each state by each ID. Any suggestions will be much appreciated. Thank you.

 

1 - time spent on V, time spent on C, 

2 - time spent on V, time spent on C

 

 

IDTimestampState
18/10/2020V
28/11/2020C
18/12/2020C
28/13/2020D
18/14/2020C
28/15/2020V
18/16/2020C
18/17/2020C
28/18/2020V
28/19/2020V
2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a measure

Measure =
VAR mind =
    CALCULATE (
        MIN ( 'Table'[Timestamp] ),
        ALLEXCEPT ( 'Table', 'Table'[ID], 'Table'[State] )
    )
VAR maxd =
    CALCULATE (
        MAX ( 'Table'[Timestamp] ),
        ALLEXCEPT ( 'Table', 'Table'[ID], 'Table'[State] )
    )
RETURN
    DATEDIFF ( mind, maxd, DAY ) + 1

Capture15.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , You can have diff between two rows  as a new column

datediff(maxx(filter(Table, [Timestamp] <[Timestamp] ),[Timestamp]),[Timestamp],Minute)

 

You can use that for more calculations

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.