Count distinct value from timeseries field for the last measure

Hi everybody.
I am using time series for storing sensors values each 30 secs for about 250 different devices,
And i try to provide an atlas chart table with the fields:
Metadata.Brand Metadata.Model and count of distinct values for the field Fir for the last Measure.
I found a solution with $lookup function, but i cant use it in query in chart.

{
	"DateTime" : ISODate("2023-06-05T16:24:56.248+02:00"),
	"Metadata" : {
		"Brand" : "truc",
		"Devn" : "M451",
		"Ip" : "10.0.1.51",
		"Model" : "XW8000",
		"Ser" : "123456789"
	},
	"Fir" : "2.1.14",
	"_id" : ObjectId("647df038fe7ca05293c70952"),
	"Hum" : 51,
	"Svc" : 26157,
	"Png" : -1,
	"Tmp" : 21,
	"Shu" : 100,
	"Sta" : 0,
	"Lsr" : 100,
	"Lmp" : 10034
}

Thx for your help