Feature scaling / Normalization formula on InfluxDB

There doesn’t seem to be a native function in InfluxDB that does that but I want to apply this simple feature scaling formula on a a measurements field values

x - min_x / max_x - min_x

I am trying to create a query like

select (sum(field_name) - min_grouped_sums) / (max_grouped_sums - min_grouped_sums) from "measurement" where time = now - 10d group by time(100s),"tag_name"

I can get the min and max values of these groups using

select min(*) from (SELECT sum("field_name") as count FROM "measurement" WHERE time = now - 10d group by time(100s),"tag_name" fill(null)) GROUP BY "tag_name"

and

select max(*) from (SELECT sum("field_name") as count FROM "measurement" WHERE time = now - 10d group by time(100s),"tag_name" fill(null)) GROUP BY "tag_name"

but I cannot compose a query that can combine both

This worked for me:

SELECT (("usage_system"-"max_count")/("usage_system"-"min_count")) from ( SELECT max("count") as "max_count", min("count") as "min_count" from (SELECT sum("usage_system") as count FROM "telegraf"."autogen"."cpu" WHERE time > :dashboardTime: AND time < :upperDashboardTime: GROUP BY time(:interval:) FILL(null)))

I cannot really see how this is going to work. Your inner query

SELECT max("count") as "max_count", min("count") as "min_count" from (SELECT sum("usage_system") as count FROM "telegraf"."autogen"."cpu" WHERE time > :dashboardTime: AND time < :upperDashboardTime: GROUP BY time(:interval:) FILL(null))

does not have a “usage_system” column so I’m surprised

SELECT (("usage_system"-"max_count")/("usage_system"-"min_count")) from (...)

works