Flux - Mapping in joined table causes no results

Hello. I have two tables “successCount” and “errorCount” which each gives the total for each respective measurement. Having said that, I created the “total” which is the sum of these two previous tables. So far, the 3 results appear without any problems. However, I now want to understand the percentage of error compared to the total (error + success) and therefore I have the final where I do the join and the map but no results are presented. What am I missing?

successCount = from(bucket: “my_db”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “success” and exists r.log_id)
|> group()
|> count()
|> yield(name: “success”)

errorCount = from(bucket: “my_db”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “error” and exists r.log_id)
|> group()
|> count()
|> yield(name: “error”)

total = union(tables: [successCount, errorCount])
|> group()
|> sum()
|> yield(name: “totalResult”)

final =
join(
tables: {total: total, erros: errorCount},
on: [“_time”]
)
|> map(fn: (r) => ({ r with _value: float(v: r.erros._value) / float(v: r.total._value) * 100.0 }))
|> yield(name: “result”)

Hi @claudiasilva and welcome to the Grafana forum. It is difficult to debug your query without having test data, but have you tried using Grafana expressions to do what you want? For example:

1 Like

Thank you for the help. It worked perfectly :slightly_smiling_face:

1 Like