How to get all values of different time series into one column

Hey,
i have 4 machines which return the current workorder they are processing. I want to post the workorder of all 4 machines into a single column. To achive this i am currently defining 4 tables
tab1= from(…)
tab2= from(…)
tab3= from(…)
tab4= from(…)
In the next step i am using the union() function to combine them into one column
union(
tables: [tab1,tab2,tab3,tab4]
)

It is working but the time to calculate the result is very long.
Is there a better way to achive this?

@Patse, there are things you can do to optimize Flux queries. The Optimize queries guide covers most of them. What InfluxDB / Flux version are you using?

Im using influx 2.0 and try to visualize all the things in Grafana 7.5

And what does your full query currently look like?

My current Query looks like this:

tab5 = from(bucket: “zone/autogen”)

|> range(start: 2021-01-01T00:00:00Z)

|> filter(fn: (r) =>

r._measurement == “M1” and

r.short == “Machine1.ID”

)

|> pivot(

rowKey:["_time"],

columnKey: [“short”,"_field"],

valueColumn: “_value”

)

|>rename(columns: {“Machine1.ID_value_str”:“Mach1”})

|> map(fn: (r) => ({

  _time: r._time,

  ID: string(v: r.Mach1),

}))

tab6 = from(bucket: “zone/autogen”)

|> range(start: 2021-01-01T00:00:00Z)

|> filter(fn: (r) =>

r._measurement == “M1” and

r.short == “Machine2.ID”

)

|> pivot(

rowKey:["_time"],

columnKey: [“short”,"_field"],

valueColumn: “_value”

)

|>rename(columns: {“Machine2.ID_value_str”:“Mach2”})

|> map(fn: (r) => ({

  _time: r._time,

  ID: string(v: r.Mach2),

}))

tab7 = from(bucket: “zone/autogen”)

|> range(start: 2021-01-01T00:00:00Z)

|> filter(fn: (r) =>

r._measurement == “M1” and

r.short == “Machine3.ID”

)

|> pivot(

rowKey:["_time"],

columnKey: [“short”,"_field"],

valueColumn: “_value”

)

|>rename(columns: {“Machine3.ID_value_str”:“Mach3”})

|> map(fn: (r) => ({

  _time: r._time,

  ID: string(v: r.Mach3),

}))

tab8 = from(bucket: “zone/autogen”)

|> range(start: 2021-01-01T00:00:00Z)

|> filter(fn: (r) =>

r._measurement == “M1” and

r.short == “Machine4.ID”

)

|> pivot(

rowKey:["_time"],

columnKey: [“short”,"_field"],

valueColumn: “_value”

)

|>rename(columns: {“Machine4.ID_value_str”:“Mach4”})

|> map(fn: (r) => ({

  _time: r._time,

  ID: string(v: r.Mach4),

}))

tab9=union(

tables: [tab5,tab6,tab7,tab8]

)