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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Time difference between rows

Hi

 

I've been trying to solve my problem for a few days, but even with research on the forum, I can't seem to make it work. 

 

Concept :

I get pings from 7 machines at varying delays. These looks like this :

 

Anthony1155_1-1666015056971.png

 

I am trying to calculate the availability of these machines in the last days. To date, I created a pie-chart that looked at the number of ping occurrences for each of the machine statuses (0-2-3-4-5-6, meaning stopped, running, in alarm, etc). The problem is that if the machine pings status "6" 60 times (every minute) for an hour, then pings status "2" once and then goes an hour without a ping, the pie-chart will show that status "6 " takes up 60 times more space, when it should be equal.
So I need to calculate the difference (in seconds) of time between two lines, per machine, since the last ping. Like this : 

Anthony1155_2-1666015527379.png

 

I tried a couple of measure and calculated column, and the closest I got is this :

 

 

 

TimedifferenceMeasure = 
VAR CurrentIndex =
    MAX ( machine_status[id] )
VAR PreviousIndex =
    CALCULATE (
        MAX ( machine_status[id] ),
        FILTER ( machine_status, machine_status[id] < CurrentIndex )
    )
VAR difference =
    DATEDIFF (
        CALCULATE (
            MAX ( machine_status[Creation Time] ),
            FILTER ( ALL ( machine_status ), machine_status[id] = PreviousIndex )
        ),
        CALCULATE (
            MAX ( machine_status[Creation Time] ),
            FILTER ( ALL ( machine_status ), machine_status[id] = CurrentIndex )
        ),
        SECOND
    )
RETURN
    IF ( difference > 43200, 43200, difference )

 

 

(The purpose of the 43200 at the end is to limit the time per status to 12 hours. Skip that, the machine is usually closed)

 

But it doesn't give me what I want. It seems to calculated only the last occurrence, meaning that frequents status get under-represented.

 

Here's the link to my file :

https://umanomed-my.sharepoint.com/:u:/g/personal/anthony_laroche_umanomedical_com/EdvcvOQ7WWRMsPGb5...

 

Thank you !

1 ACCEPTED SOLUTION
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

Does this one here help you?

 

Ranking Column in your case should be the [Created On] column, where as the Grouping Column is [id]

DateDiffColumnWithoutIndex = 
DATEDIFF (
   'TableName'[RankingColumn],
    CALCULATE (
        MIN ( 'TableName'[RankingColumn] ),
        FILTER ( 'TableName', 'TableName'[RankingColumn]  > EARLIER ( 'TableName'[RankingColumn]  ) ),
        FILTER ( 'TableName', 'TableName'[GroupingColumn] = EARLIER ( 'TableName'[GroupingColumn] ) )
    ),
    SECOND
)

 

Doing this in a calculated column might take quite some resources and time. Maybe consider adding this column in Power Query instead. This one here, might help you in that case.

 

Let me know if this helps!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks tackytechtom ! 

I ended up doing it in Power Query like in your link. A couple changes to adapt to my situation and it works now ! 

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

Does this one here help you?

 

Ranking Column in your case should be the [Created On] column, where as the Grouping Column is [id]

DateDiffColumnWithoutIndex = 
DATEDIFF (
   'TableName'[RankingColumn],
    CALCULATE (
        MIN ( 'TableName'[RankingColumn] ),
        FILTER ( 'TableName', 'TableName'[RankingColumn]  > EARLIER ( 'TableName'[RankingColumn]  ) ),
        FILTER ( 'TableName', 'TableName'[GroupingColumn] = EARLIER ( 'TableName'[GroupingColumn] ) )
    ),
    SECOND
)

 

Doing this in a calculated column might take quite some resources and time. Maybe consider adding this column in Power Query instead. This one here, might help you in that case.

 

Let me know if this helps!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.