Smart query to sum / avg

Hi all,

Very first day of login and using this space. Please excuse if i do not know my way around.

I am a new user of Grafana and looking for some help with a query.

I have two data feeds coming in and the data is not very consistent, it should be a per minute read, but there are times when data is missing all together or some times when there are two readings in a minute.

I am creating a panel with 3 queries. Query A and B are simple and show the average if multiple data in a minute;
SysName: “A” AND ModuleIndex: “8” AND ModuleSubIndex: “2”
SysName: “B” AND ModuleIndex: “8” AND ModuleSubIndex: “2”

Query 3 is
(SysName: “A” AND ModuleIndex: “8” AND ModuleSubIndex: “2”) OR (SysName: “B” AND ModuleIndex: “8” AND ModuleSubIndex: “2”)

Query 3 is where i am having issues, as i do not know how to make the query smart enough that if either A or B has a value and the other does not then use the previous value rather than taking null as a 0 and spoiling the sum/avg.
Another situation is when either of the feed has more than one reading in a minute, need a way to average it out before adding it to the other feed for the data to be correct.


What is your datasource?

elastic db I believe.