TickScript issues with no field or tag exists for a variable

I am trying to calculate error percentage but getting the error message of no tag or field exists.I am not sure why I am getting the no field or tag error pops out but this error_rate is a variable I am using to calculate error percentage and is not part of influx DB to be associated with any tag or field. Can someone help me with debugging this or letting me know where I am going wrong.

Error I am getting : E! error evaluating expression for level CRITICAL: no field or tag exists for error_rate


var unit = 1m
var rateThreshold = 0
/var error_rate = 0


var data = stream
.prefix('Messages: ')

// get failed messages

var FM = data
|where(lambda: “status” == ‘FAILED’)
.prefix('Failed Messages: ')

// get completed messages

var TM = data
|where(lambda: “status” == ‘COMPLETE’)
.prefix('Completed Messages: ')

//Joining two to get error percentage.

|eval(lambda: if((“FM.count” + “TM.count”) == 0, 0, ((“FM.count”)/(“FM.count” + “TM.count”))*100))
.prefix('Error rate: ')

var alert = data
.id(’{{ index .Tags “service” }}-{{ index .Tags “topic” }}’)
.message(’{{ .Level }}: Error rate threshold exceeded for {{ index .Tags “service” }}-{{ index .Tags “topic” }} for {{ index .Fields “messageCount” }} messages’)
// .crit(eval(lambda: if((“FM.count” + “TM.count”) == 0, 0, ((“FM.count”)/(“FM.count” + “TM.count”))*100)) > rateThreshold)
.crit(lambda: “error_rate” > rateThreshold)


.id(’{{ index .Tags “service” }}-{{ index .Tags “topic” }}’)
//write to a log file.