Select to view content in your preferred language

FeatureLayer Calculate SQL Syntax

535
2
Jump to solution
11-18-2021 12:33 PM
mapmcburney
Occasional Contributor

Hello I have a Feature Layer with three integer fields (A, B, and C)

I want to calculate the percentage between A and B. The following will run but I only get values of 100 or 0. Nothing in between, and manual calculations prove that there are valid values between 100 and 0.

overlay_result_layer.calculate(where= "1=1",calc_expression={"field": "C", "sqlExpression":"(B/A)*100"})
 
Can anyone see what is wrong with my syntax?
 
For additional info, I run the calculation below right before without errors perfectly fine;
 
overlay_result_layer.calculate(where= "1=1",calc_expression={"field": "B", "sqlExpression": "D * 247.105"})
 

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

It's the integers. Take your first expression, (B/A) * 100. Since B/A evaluates first, you're stuck with whatever rounded integer value results from the division. That is, 0 or 1, which then multiplied by 100 gives you 0 and 100, respectively.

Try instead, (B*100)/A. By multiplying your integer first, you avoid truncating the divided value as drastically.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

It's the integers. Take your first expression, (B/A) * 100. Since B/A evaluates first, you're stuck with whatever rounded integer value results from the division. That is, 0 or 1, which then multiplied by 100 gives you 0 and 100, respectively.

Try instead, (B*100)/A. By multiplying your integer first, you avoid truncating the divided value as drastically.

- Josh Carlson
Kendall County GIS
mapmcburney
Occasional Contributor

You are a legend! Thank you!

0 Kudos