# How to get the latest timestamp of value change (0\>1 or 1\>0)

**URL:** https://community.influxdata.com/t/how-to-get-the-latest-timestamp-of-value-change-0-1-or-1-0/24633
**Category:** InfluxDB 2
**Tags:** query, flux
**Created:** [April 13, 2022, 8:29am UTC](https://community.influxdata.com/t/how-to-get-the-latest-timestamp-of-value-change-0-1-or-1-0/24633 "2022-04-13T08:29:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dewenni](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/dewenni/32/9361_2.png) [@dewenni](https://community.influxdata.com/u/dewenni)
#### Post date: [April 13, 2022, 8:29am UTC](https://community.influxdata.com/t/how-to-get-the-latest-timestamp-of-value-change-0-1-or-1-0/24633/1 "2022-04-13T08:29:31Z")

</div>

Hi,

I try to get the following information out of my measurement:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/5/59996a886a38826e553977ee056be1848f70eebb.png)

when was the last value change from “0” to “1” and when was the last value change from “1” to “0”.  
I study already the flux help, but I haven’t found a solution for that kind of query.  
Simply using min() and max() will not work because there are equal values in-between. So I have to search for the value differences.

Any Idea how to solve this?

thanks!

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [April 13, 2022, 7:01pm UTC](https://community.influxdata.com/t/how-to-get-the-latest-timestamp-of-value-change-0-1-or-1-0/24633/2 "2022-04-13T19:01:46Z")

</div>

Hello @dewenni,  
Have you tried:

> **[monitor.stateChanges() function | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/monitor/statechanges/)**
>
> monitor.stateChanges() detects state changes in a stream of data with a \_level column and outputs records that change from fromLevel to toLevel.

?  
Thanks
