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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
xsaldana
Regular Visitor

Finding the difference between the time from first and last occurrence

Hello! I am trying to find the difference in unixtime from when a sensor was first registered to when it was registered again. I color coated the chart to empashize the sensor type. The "Time since last reading" column is the one that I am attempting to create and the one to the right of it has the equations. I am having issue because the pH sensor has 3 readings at different depths, but I only take the difference when the three readings appear again. Opposingly, I only recieve one readign for the ambient temp, water temp, and oxygen level. Any suggestions?

 

xsaldana_2-1652141352498.png

 

 

 

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @xsaldana ,

 

Please try the following formula:

 

Column = 
VAR _current = Data[unix time]
VAR _previous =
    MAXX (
        FILTER (
            Data,
            Data[sensor] = EARLIER ( Data[sensor] )
                && Data[Depth (m)] = EARLIER ( Data[Depth (m)] )
                && Data[unix time] < EARLIER ( Data[unix time] )
        ),
        Data[unix time]
    )
RETURN
    IF ( ISBLANK ( _previous ), BLANK (), _current - _previous )

vkkfmsft_0-1652335087779.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Hi @xsaldana ,

 

Please try the following formula:

 

Column = 
VAR _current = Data[unix time]
VAR _previous =
    MAXX (
        FILTER (
            Data,
            Data[sensor] = EARLIER ( Data[sensor] )
                && Data[Depth (m)] = EARLIER ( Data[Depth (m)] )
                && Data[unix time] < EARLIER ( Data[unix time] )
        ),
        Data[unix time]
    )
RETURN
    IF ( ISBLANK ( _previous ), BLANK (), _current - _previous )

vkkfmsft_0-1652335087779.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@xsaldana Seems like your > sign should be a < sign. And, you could use your Index potentially instead of unix time value for finding previous. Also, not sure about that last ). How many rows are there? Also, you *might* get better performance from this variation:

Column = 
var _sensor = Data[sensor]
var _current = Data[unix time]
var _previous = MAXX(FILTER(Data,
                       Data[sensor] = _sensor &&
                       Data[unix time] < _current
               ),Data[unix time])
return 
_current - _previous

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@xsaldana Seems like you want something like MTBF: See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous

 

Also, this might be handy: Unix2UTC and UTC2Unix - Microsoft Power BI Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thank you! unfortunately, your suggestion didn't work for me. It freezes powerbi. 

Below is what I did. Any suggestions? Additionally, my time needs to stay in unix.

Column = 

var _current = Data[unix time]

var _previous = MAXX(FILTER(Data,

                       Data[sensor]=EARLIER(Data[sensor]) &&

                       Data[unix time]>EARLIER(Data[unix time])

               ),Data[unix time])

return 

_current - _previous )

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.