Update:
I now have found a solution by experimenting with the experimental.to function.
Having changed the query to:
last = from(bucket: "testtelegraf")
|> range(start: -7d)
|> filter(fn: (r) => r["topic"] == "Import")
|> aggregateWindow(every: 1d, fn: last, createEmpty: false)
first = from(bucket: "testtelegraf")
|> range(start: -7d)
|> filter(fn: (r) => r["topic"] == "Import")
|> aggregateWindow(every: 1d, fn: first, createEmpty: false)
join(
tables: {lastusage: last, firstusage: first},
on: [
"_time",
"topic",
],
)
|> map(
fn: (r) => ({
_value: r._value_lastusage - r._value_firstusage,
_endvalue: r._value_lastusage,
_time: r._time,
_measurement: "solar_daily",
}),
)
|> to(
bucket:"test_daily",
org:"my-org",
fieldFn: (r) => ({"_value": r._value, "_endvalue": r._endvalue})
)
Now results in basically 2 tables on the test_daily bucket:
Apparently the _field is now tagged with “_value” or “_endvalue” according to which value there is in the “_value” field.
So,I now have saved both the daily usage and the end-value in tables, and can use that in reports, so that is fine.
Still puzzled why I can’t see to create a single table with both values in each row, just like the result of the initial query. If somebody would show me how to do that (and how I seem not to understand to work with fields and tags), that would be great!