# How to iterate over device datapoint to update certain attributes?

**URL:** <https://forums.losant.com/t/how-to-iterate-over-device-datapoint-to-update-certain-attributes/5136>\
**Category:** Help\
**Tags:** workflow, device\
**Created:** [July 3, 2023, 7:39am UTC](https://forums.losant.com/t/how-to-iterate-over-device-datapoint-to-update-certain-attributes/5136 "2023-07-03T07:39:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamino\_Schorcht](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@Tamino\_Schorcht](https://forums.losant.com/u/Tamino_Schorcht)\
**Post date:** [July 3, 2023, 7:39am UTC](https://forums.losant.com/t/how-to-iterate-over-device-datapoint-to-update-certain-attributes/5136/1 "2023-07-03T07:39:08Z")

</div>

Hello everyone,

I’m new working with Losant and am stuck at a problem, I’d think should be easy to solve.  
I have multiple devices with 3 sensors each. Every few hours, they upload the sensorreadings of the passed time to a platform which I can access through an API. Unfortunately, I need to get the data column by column (each sensor at a time). I update my losant-devices and get the next cloumn. The resulting data looks like this:

 ![screenshot_data](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/13094d25ee2bd343a1851cb806ccaec9291b7e28.png)  
Now, after updating the sensor-readings, I wanted to calculate the 2 missing attributes. E.g. if value1\>value2, value5 = “ok”. Or value4=1-(value1/value2).  
I thought I could iterate over the datapoints, starting by the latest, update each entry until I reach an entry that has value4 and value5 already set, but I cant figure out how. The “Data: Time Series” and “Data: Gauge” nodes only fetch one attribute at a time and I need all 5. I hope you can help me ☹  
If you need additional info, please let me know.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Turner](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sebastian_turner/32/4024_2.png) [@Sebastian\_Turner](https://forums.losant.com/u/Sebastian_Turner)\
**Post date:** [July 3, 2023, 2:58pm UTC](https://forums.losant.com/t/how-to-iterate-over-device-datapoint-to-update-certain-attributes/5136/2 "2023-07-03T14:58:27Z")

</div>

Hi @Tamino_Schorcht and welcome to the Losant forums!

I’m working on an example of how to accomplish this. I’ll get back with you shortly!

---

<div class="post-metadata">

**Author:** ![Sebastian\_Turner](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sebastian_turner/32/4024_2.png) [@Sebastian\_Turner](https://forums.losant.com/u/Sebastian_Turner)\
**Post date:** [July 3, 2023, 9:13pm UTC](https://forums.losant.com/t/how-to-iterate-over-device-datapoint-to-update-certain-attributes/5136/3 "2023-07-03T21:13:49Z")

</div>

I’m unsure of the considerations that need to be made in your initial workflow that fetches and formats this data, so I’m going to approach this from the perspective of a downstream process or a separate workflow that’s triggered after this data is in place.

In our next release, the [Data: Time Series](https://docs.losant.com/workflows/data/time-series/) and [Data: Gauge Query](https://docs.losant.com/workflows/data/gauge-query/) nodes are being updated to return multiple attributes.

In the meantime, for a single device, you can use the [Losant API Node](https://docs.losant.com/workflows/data/losant-api/) with the [Device: Get State](https://docs.losant.com/rest-api/device/#get-state) endpoint, which returns the most recent state reports for a given device. This can be set to return all state entries since a specified time value (`since`, in epoch), or a specified number of the most recent entries (`limit`). If you have a predictable number of device state reports (unique timestamp values) after each run of the initial workflow, you could use that number as your `limit` value. Alternatively, you could utilize [workflow storage](https://docs.losant.com/workflows/overview/#workflow-storage) to maintain an epoch time value from the last execution to use as your `since` parameter.

For multiple devices, you can use the Losant API Node with the [Data: Time Series Query](https://docs.losant.com/rest-api/data/#time-series-query) endpoint. This would require formatting a [request body](https://docs.losant.com/rest-api/data/#request-body-a-nametimeseriesquery-bodya) in JSON format.

Given these values, you should be able to perform the calculations in question (using [conditional block helpers](https://docs.losant.com/workflows/accessing-payload-data/#conditional-block-helpers) or a [Function Node](https://docs.losant.com/workflows/logic/function/) formula) and then, within a loop, use the [Device: Update Node](https://docs.losant.com/workflows/data/update-device/) to populate the remaining two attributes.

Please let us know if you have any further questions!

---

<div class="post-metadata">

**Author:** ![Tamino\_Schorcht](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@Tamino\_Schorcht](https://forums.losant.com/u/Tamino_Schorcht)\
**Post date:** [July 4, 2023, 6:12am UTC](https://forums.losant.com/t/how-to-iterate-over-device-datapoint-to-update-certain-attributes/5136/4 "2023-07-04T06:12:31Z")

</div>

Thank you for your response, it was very helpful! I was able to implement a solution using the Losant API Node with the Data: Time Series Query and a following Function Node as you suggested!  
Your approach of a downstream process utilizing a seperate workflow was exactly what I was trying to achieve and it is great to hear, that this more complex approach won’t be necessary anymore, once the Data:… Nodes are updated 🙂
