Hi,
I have a problem with getting the correct aggregation / join / pivot of my data.
I know aggregation, join and pivot from relational dbs, excel or whatever but it seems that influxdb works somehow different.
Example of my base data:
light,category=toggle,floor=2nd,full_name=Office_Light_Desk_OnOff,groupaddress=1/2/207,host=telegraf,object=desk,room=Office,source=1.2.60 value=false 1757789306604644331
light,category=toggle,floor=2nd,full_name=Office_Light_Top_OnOff,groupaddress=1/2/200,host=telegraf,object=top,room=Office,source=0.0.254 value=false 1757790807432413619
light,category=toggle,floor=2nd,full_name=Office_Light_Door_OnOff,groupaddress=1/2/210,host=telegraf,object=door,room=Office,source=0.0.254 value=true 1757790807600401816
…
with the following flux lines
from(bucket: “sourceData”)
|> range(start: start)
|> filter(fn: (r) => r._measurement == “light” and r.category == “toggle” and r.room == “Office”)
|> aggregateWindow(every: aggtime, fn: last, createEmpty: true)
|> set(key: “_field”, value: “onoff”)
|> fill(usePrevious: true)
|> pivot(rowKey: [“_time”], columnKey: [“_field”], valueColumn: “_value”)
I am getting the following result
,result,table,_start,_stop,_time,_measurement,category,floor,full_name,groupaddress,host,object,room,source,onoff
,0,2025-09-14T11:28:32.077162988Z,2025-09-15T11:28:32.077162988Z,2025-09-14T11:29:00Z,light,toggle,2nd,Office_Light_Top_OnOff,1/2/200,telegraf,top,Office,0.0.254,false
,1,2025-09-14T11:28:32.077162988Z,2025-09-15T11:28:32.077162988Z,2025-09-14T11:29:00Z,light,toggle,2nd,Office_Light_Desk_OnOff,1/2/207,telegraf,desk,Office,0.0.254,true
,2,2025-09-14T11:28:32.077162988Z,2025-09-15T11:28:32.077162988Z,2025-09-14T11:29:00Z,light,toggle,2nd,Office_Light_Door_OnOff,1/2/210,telegraf,door,Office,0.0.254,false
My intention to get is only 1 row per timestamp:
2025-09-14T11:28:32.077162988Z,2025-09-15T11:28:32.077162988Z,2025-09-14T11:29:00Z,light,toggle,2nd,Office_Light_Top_OnOff,1/2/200,telegraf,top,Office,0.0.254,false, Office_Light_Desk_OnOff,1/2/207,desk,true Office_Light_Door_OnOff,1/2/210,door,false
Normally in a pivot-table I would specify the time, floor and room in the rows and the other infos in the coloums. But in flux it seems to be different.
- Is it because I am getting 3 tables and I have to union() or join() the tables first?
- Any ideas how to realize it here?