Perform mathematical operations within a function with irregular timestamp data

I have several meters which log data upon change in value, and as such, they do not receive data with the exact same timestamp.

I now wish to generate a chart displaying the maximum combined value of several meters over time, and have decided to go with 15 minute durations. In addition to adding the values, I might need to subtract a deduct meter or multiple a given meter by a scaling constant, but this shouldn’t be any different.

https://docs.influxdata.com/influxdb/v1.5/troubleshooting/frequently-asked-questions/#how-do-i-perform-mathematical-operations-within-a-function gives the following example.
SELECT MEAN("difference") FROM (SELECT "dogs" - "cat" AS "difference" FROM "pet_daycare")

So, I try the following:
SELECT max(allmeters) FROM (SELECT 0.4*meter1 + meter2 - 0.2*meter3 AS allmeters FROM meters WHERE time >= '2018-04-28' AND time <= '2018-05-02') GROUP BY TIME(900s) fill(previous)

The problem, however, is more often than not, I do not have data for the three meters at a given timestamp, and thus have no data.

I suppose one solution would be to include a GROUP BY with a smaller (but big enough) group by time, however, this is not really accurate, probably inefficient, and seems like a kludge solution. Ideally, my subquery would use the previous value (or better yet linear between the previous and next value), but I don’t know whether this is possible.

How can this be accomplished? Thank you

You currently use fill(previous) for the main query, where you want to use it for the subquery. I don’t think this is possible.

Instead of using a subquery, use the subquery as a main query with INTO, so you can store the result of your subquery in a different measurement.

After your ‘subquery’ is stored in a measurement, use your custom function to get max(allmeters)

Thanks confususs,

I’ve never played with INTO before, and just read up on it. I don’t, unfortunately, think it is the way to go. This would store the results in a table, no?

Maybe using fill(previous) in the subquery is the way to go?

PS. I am pretty sure fill(previous) is possible to be used in the main query, however, it doesn’t seem to be applicable to my needs.