Select to view content in your preferred language

Calculation with if clause dependent to other fields

579
1
Jump to solution
08-12-2022 10:36 AM
by Anonymous User
Not applicable

Hello,

I need help with writing a function. I am trying to calculate the dollar per acre spending on some products. The data behind is from USDA's Cropscape data. Count is how many pixels you have in a defined area (30m x 30m) which I converted to acres without any hustle.

Now I am trying to write this, with my limited vba knowledge, but don't know how to

DollarPerAcre=

IF CLASS_NAME = Alfalfa

THEN Acres * 100

ELSE IF CLASS_NAME = *Wheat* (contains "Wheat" in it)

THEN Acres * 80

ELSE

0

I would appreciate any help

h_deniz_ozturk_0-1660325375628.png

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum

code block:

def get_factor(class_name):
    if class_name == "Alfalfa":
        return 100
    if "Wheat" in class_name:
        return 80
    return 0

 

DollarPerAcre = get_factor(!CLASS_NAME!) * !Acres! 

Have a great day!
Johannes

View solution in original post

0 Kudos
1 Reply
JohannesLindner
MVP Alum

code block:

def get_factor(class_name):
    if class_name == "Alfalfa":
        return 100
    if "Wheat" in class_name:
        return 80
    return 0

 

DollarPerAcre = get_factor(!CLASS_NAME!) * !Acres! 

Have a great day!
Johannes
0 Kudos