Please do not post duplicate questions on the forum.
Noob not getting the syntax for average of tag data - General Discussion - Inductive Automation Forum
It looks like you're combining scripting and expression syntax. The expression and scripting languages are completely different. The function you are using is for scripting, but you are trying to use it in an expression which doesn't work.
I typically hold shift datetimes in tags whether they are memory tags or expression tags. You can bind the shift start/end tags to custom properties in a vision project if needed. Write your script and test it in the script console under Tools → Script Console first. (format scripts using the </>
button in the forum).
# tag path for line is a string
LineTag = '[default]Hi Speed Nordson/Line Speed FPM 1'
# If you have shift start/end tags, then bind the values to your custom properties
date1= event.source.parent.startDate5AM
date2= event.source.parent.stopDate2PM
event.source.text = system.tag.queryTagCalculations(paths=[LineTag],calculations = ["Average"],startDate=date1,endDate=date2)
Visit www.inductiveuniversity.com and go through the lessons if you haven't already.
EDIT: You have to import the vision window to use those custom properties in the script console, so probably easier to test in button or something. I started down one path of explanation and changed my mind midway.