# Project Library Script - Return outside function SyntaxError

**URL:** <https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [September 22, 2025, 8:52pm UTC](https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852 "2025-09-22T20:52:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Dos\_Santos](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Miguel\_Dos\_Santos](https://forum.inductiveautomation.com/u/Miguel_Dos_Santos)\
**Post date:** [September 22, 2025, 8:52pm UTC](https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852/1 "2025-09-22T20:52:48Z")

</div>

Hello, I have been working away at doing some way of creating a simple script to do some query Tag calculations to take two tags, sum them, and then divide one sum by the other and multiply by 100. I put the complete script below. The problem I have is that on trying to perform the final calculation and returning it “return float(sum\_value\_tag1) / float(sum\_value\_tag2) \* 100,” on the the 4th last line of the below I get a “‘return’ outside function” that I am struggling to fix. I tried a similar script in the script console and it worked, but putting it in this format I get the a Syntaxerror that is not apparent to me.

```python
def calculateEfficiency(tagPath1, tagPath2, timeMinutes):
# Define the tag paths
# tag_path_1= Total Power for Historian Data Points
# tag_path_2= Total Flow for Historian Data Points
   
# Define the time range
    start_date = system.date.addMinutes(system.date.now(), -timeMinutes) # Last X minutes
    end_date = system.date.now()
   
# Query the sum for each tag individually
# The 'sum' calculation will return the sum of values over the specified time range
sum_tag1_data = system.tag.queryTagCalculations(
    paths=[tag_path_1],
    calculations=['sum'],
    startDate=start_date,
    endDate=end_date,
    noInterpolation=True
)

# The 'sum' calculation will be in the column named 'sum'
sum_value_tag1 = sum_tag1_data.getValueAt(0, "sum")

# The 'sum' calculation will return the sum of values over the specified time range
sum_tag2_data = system.tag.queryTagCalculations(
    paths=[tag_path_2],
    calculations=['sum'],
    startDate=start_date,
    endDate=end_date,
    noInterpolation=True
)

# The 'sum' calculation will be in the column named 'sum'
sum_value_tag2 = sum_tag2_data.getValueAt(0, "sum")
   

if sum_value_tag2 != 0:
# Perform the division and multiply by 100
    return float(sum_value_tag1) / float(sum_value_tag2) * 100
else:
    system.util.getLogger("LoggerName").warn("Cannot divide by zero: Sum of Tag2 is zero.")
    return None

```

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [September 22, 2025, 8:54pm UTC](https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852/2 "2025-09-22T20:54:57Z")

</div>

You don’t have the indentation correct.

```python
def calculateEfficiency(tagPath1, tagPath2, timeMinutes):
	# Define the tag paths
	# tag_path_1= Total Power for Historian Data Points
	# tag_path_2= Total Flow for Historian Data Points
	   
	# Define the time range
    start_date = system.date.addMinutes(system.date.now(), -timeMinutes) # Last X minutes
    end_date = system.date.now()
   
	# Query the sum for each tag individually
	# The 'sum' calculation will return the sum of values over the specified time range
	sum_tag1_data = system.tag.queryTagCalculations(
		paths=[tag_path_1],
		calculations=['sum'],
		startDate=start_date,
		endDate=end_date,
		noInterpolation=True
	)

	# The 'sum' calculation will be in the column named 'sum'
	sum_value_tag1 = sum_tag1_data.getValueAt(0, "sum")

	# The 'sum' calculation will return the sum of values over the specified time range
	sum_tag2_data = system.tag.queryTagCalculations(
		paths=[tag_path_2],
		calculations=['sum'],
		startDate=start_date,
		endDate=end_date,
		noInterpolation=True
	)

	# The 'sum' calculation will be in the column named 'sum'
	sum_value_tag2 = sum_tag2_data.getValueAt(0, "sum")
	   

	if sum_value_tag2 != 0:
	# Perform the division and multiply by 100
		return float(sum_value_tag1) / float(sum_value_tag2) * 100
	else:
		system.util.getLogger("LoggerName").warn("Cannot divide by zero: Sum of Tag2 is zero.")
		return None

```

---

<div class="post-metadata">

**Author:** ![Miguel\_Dos\_Santos](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Miguel\_Dos\_Santos](https://forum.inductiveautomation.com/u/Miguel_Dos_Santos)\
**Post date:** [September 22, 2025, 9:04pm UTC](https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852/3 "2025-09-22T21:04:57Z")

</div>

Thank-you for the response jpark. I was thinking it was that, but have done and redone the indentation for the last part, ensuring that i don’t have spacing and still get the error, and why I ended up here.

Is there anyway you can show me the error of the below snippet.

```python
if sum_value_tag2 != 0:
    # Perform the division and multiply by 100
    return float(sum_value_tag1) / float(sum_value_tag2) * 100
else:
    system.util.getLogger("LoggerName").warn("Cannot divide by zero: Sum of Tag2 is zero.")
    return None

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 22, 2025, 9:07pm UTC](https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852/4 "2025-09-22T21:07:30Z")

</div>

> [@Miguel\_Dos\_Santos](#):
>
> error of the below snippet.

It isn't indented, which is required under a `def`.

---

<div class="post-metadata">

**Author:** ![Miguel\_Dos\_Santos](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Miguel\_Dos\_Santos](https://forum.inductiveautomation.com/u/Miguel_Dos_Santos)\
**Post date:** [September 22, 2025, 9:44pm UTC](https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852/5 "2025-09-22T21:44:32Z")

</div>

Thank-you that helps, and will look that up and learn.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 22, 2025, 11:59pm UTC](https://forum.inductiveautomation.com/t/project-library-script-return-outside-function-syntaxerror/110852/6 "2025-09-22T23:59:40Z")

</div>

[![](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/a/5a2522eaeefdcfbe2d018b6d55073fba6c234707.png) ](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/a/5a2522eaeefdcfbe2d018b6d55073fba6c234707.png)

On any of the editors you can turn on display of tabs and whitespace. This will help you check indentation.
