is there a way to find out if a from() returned an empty set?

I am working on a larger script with several from() statements returning several tables

x = from()

|> range(…)

|> filter(fn: (r ) => r._measurement == “x” )

|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: “_value”)

y = from()

|> range(…)

|> filter(fn: (r ) => r._measurement == “y )

|> pivot(rowKey:[”_time"], columnKey: ["_field"], valueColumn: “_value”)

z = from()

|> range(…)

|> filter(fn: (r ) => r._measurement == “z” )

|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: “_value”)

I want to join all the different tables at the end with join(), but it could happen that some of the tables are empty. In this case I want to ignore the empty tables in the join() operation and just join the others.

Unfortunately a join will drop all my results in case any of x,y,z returned an empty set.

I want to include some conditional logic like

united_tables = if (exists x) then join(x,y) else y

I have no idea how to implement the “exists x” part. I have tried using the count() function but it will fail, if the original x returned no results. Any way to check if a table is not empty?