Could not extract a single result from a device_id

Currenty I am developing a .Net web api service using influxDb. I have three values that I want to have latitude, longtitud and device_id. For some reason when I input them into influx it seperates them into two tables.However I am taksed with creating a route which when given a device_id in the form of a GUID I will return all the results associated with this device_id.

Whenever I execute the Flux query and provide a GUID it returns the list of all the measurements, with device_id null. The actual one that I want to recieve is the one circled in red with the device_id, longtitude and latitude present. I have tried using and instead of or in the filter section for fileds but it gives me an empty result. I am new to Flux and Influx and I have been really struggling with this task any suggestions or help would be really appreciative. Thank you in advance.

Flux query and method used:
public async Task GetByID(Guid id)
var results = await _service.QueryAsync(async query =>
var flux = “from(bucket:“animal_logs”) " +
“|> range(start: -6h) " +
“|> filter(fn: (r) => " +
“r._measurement == “animal_data”)” +
$”|> filter(fn: (r) => (r._field == “latitude”) or (r._field == “longtitude”) or (r._field == “device_id” and r._value == “{id}”))” +
$”|> filter(fn: (r) => r.animal == “test-animal”)"+
“|> pivot(rowKey: [”_time"], columnKey: ["_field"], valueColumn: “_value”)" +
“|> group(columns: [“device_id”, “latitude”, “longtitude”])” +
“|> yield()”;

            var tables = await query.QueryAsync(flux, "");
            return tables.SelectMany(table =>
                    table.Records.Select(record =>
        return results;


I suppose the device_id = null are from the tables without the device_id but I thought it will join them together by pivot and group and list all the object that match the guid.

Hello @Alexander_Petrov,
If you’re grouping by device_id, latitude, and longitude then you’ll be creating more tables, separating out your data. If you want your data all together then you want to remove your group.

This article might be helpful for understanding grouping better: