First of all, I’d like to be able to perform an operation like “variable1 / variable2 / constant”.
depending on the designated time step. In other words, the calculation can be performed by day, month or year. In the script “aggregateWindow(every: 1d” 1d would be a variable on Grafana (1d/1m/1y)
The above calculation must be performed according to this aggregation window.
In addition to this. I have a third variable that must compete with variable 2. If var2 > var3 then variable 2 is retained. If var3 > var2 then variable 3 is retained.
The calculation can be either “var1 / var2 / constant” or “var1 / var3 / constant”.
You can create a Grafana dashboard variable that includes the three duration values and use it in your query. The values of the variable will be strings, so you have to cast them to duration values. For example:
Is var3 a field value returned by your query or is it a constant. Since you’re querying two fields, I’ll assume var3 is a constant. In your map() function, you can assign a variable that returns the greater of the two values (var2 vs var3) using the math.mMax() function.
It’s the combination of union() |> pivot() that gives you what you’d expect from a join, but in a much more performant way. Your query would look something like this:
@Yohan, there’s a way you can do this without having to join streams together. Joins are incredibly expensive operations and I avoid them when I can. Since both fields are queried from the same data source, you can query both fields in a single filter() call. You can then pivot them into columns so you can compare them per row. Rather than if/else logic to find the greater of the two values, you can import the math package and use math.mMax: