Kapacitor Tickscript aggregate and combine collection of multiple instance of the processes into one

This is an important use case for us.

How can one write a stream tickscript which will aggregate and combine collection of multiple (instance#) of the same Process into one and calculate average Percent_Processor_Time.

Example: measurement Process has instance tag which stores name of the .exe like:

instance, Percent_Processor_Time
WmiPrvSE#1, 1.0
WmiPrvSE#2, 0.1
WmiPrvSE#3, 0.3
instance, Percent_Processor_Time
Chrome#1, 1.0
Chrome#2, 0.0
Chrome#3, 2.0

Goal is to combine same Process into one and get the Average:

instance, Percent_Processor_Time
WmiPrvSE, 0.46
Chrome, 1.00

I tried the creating a stream tickscript but it was not giving any output.
So i tried batch and it is yielding an output but not grouping the instance into one.
Do i have to use regex explicitly on instance?

Objective is to get .exe cpu usage divided by the number of cpu present on the server.

// Get Percent_Processor_Time for each process
        var process = batch
            |query('SELECT Percent_Processor_Time as cpu_time FROM "test"."autogen"."Process"')
                .period(1m)
                .every(1m)
                .groupBy('instance', 'host')
            |mean('cpu_time')
                .as('cpu_time')

    // This is to get number of cpus from each host
        var system = batch
            |query('SELECT n_cpus as n_cpus FROM "test"."autogen"."system"')
                .period(15m)
                .every(1m)
                .groupBy('host')
            |last('n_cpus')
                .as('n_cpus')

        var joined_data = process
            |join(system)
                .as('process', 'system')
                .on('instance')
                .tolerance(20s)

        var perform = joined_data
            |eval(lambda: "process.cpu_time" / "system.n_cpus")
                .as('mean')
                .keep()
            |influxDBOut()
                .database('test')
                .measurement('perform')