# Average of values for a particular datetime

**URL:** <https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 2, 2023, 12:00pm UTC](https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122 "2023-01-02T12:00:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divya\_Chorge1](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Divya\_Chorge1](https://forum.inductiveautomation.com/u/Divya_Chorge1)\
**Post date:** [January 2, 2023, 12:00pm UTC](https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122/1 "2023-01-02T12:00:37Z")

</div>

I have many number of entries or records of data in a day I just wanted to show the average of value for a particular day on timeseries chart in perspective ignition.  
I am not able to show the average value for a particular day.  
Should we create a code for the same.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 2, 2023, 12:12pm UTC](https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122/2 "2023-01-02T12:12:04Z")

</div>

If your data is coming from a SQL query then you should use the SQL AVG() function to return the data in the format required.

---

<div class="post-metadata">

**Author:** ![Divya\_Chorge1](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Divya\_Chorge1](https://forum.inductiveautomation.com/u/Divya_Chorge1)\
**Post date:** [January 2, 2023, 1:28pm UTC](https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122/3 "2023-01-02T13:28:12Z")

</div>

I have used the SQL Avg function it is returning all the average data I just needed the specific one day data to show as selected.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 2, 2023, 1:39pm UTC](https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122/4 "2023-01-02T13:39:27Z")

</div>

Please show your SQL query.  
Use the `</>` code formatting button to preserve code indentation and apply syntax highlighting.

---

<div class="post-metadata">

**Author:** ![ShaneH](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@ShaneH](https://forum.inductiveautomation.com/u/ShaneH)\
**Post date:** [January 3, 2023, 2:07pm UTC](https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122/5 "2023-01-03T14:07:48Z")

</div>

Hi-

You might consider grouping by the date:

```auto
SELECT 
   AVG(myValue) AS avgValue, 
   CAST(myDateTime AS DATE) AS dateOnly 
FROM myTable
GROUP BY CAST(myDateTime AS DATE)

```

This would give you the average value for each date in the table.  
Or if you need a specific date:

```auto
SELECT 
   AVG(myValue) AS avgValue 
FROM myTable
WHERE CAST(myDateTime AS DATE) = '2022-01-01'

```

It would probably be best to parameterize the date value with a binding.

HTH.  
-Shane

---

<div class="post-metadata">

**Author:** ![Divya\_Chorge1](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Divya\_Chorge1](https://forum.inductiveautomation.com/u/Divya_Chorge1)\
**Post date:** [January 3, 2023, 3:41pm UTC](https://forum.inductiveautomation.com/t/average-of-values-for-a-particular-datetime/68122/6 "2023-01-03T15:41:57Z")

</div>

Thanks
