EZ Exporter Calculated Fields - Conditional Expressions

Conditional expressions allow you to include logic when generating your report.

AVAILABLE OPERATORS

  • if ("this value" if "condition" else "", must be used with "else")
  • else ("this value" if "condition" else "this other value", must be used with "if")
  • not (if not "condition", not 1 == 1 -> False, not 1 == 2 -> True)
  • and (both conditions must be True, if "condition1" and "condition2", if 1 == 1 and 1==2 -> False)
  • or (either condition can be True, if "condition1" or "condition2", if 1 == 1 or 1 == 2 -> True)
  • > (greater than, if 3 > 1 -> True)
  • < (less than, if 1 < 3 -> True)
  • >= (greater than or equal to, if 3 >=3 -> True)
  • <= (less than or equal to, if 3 <= 3 -> True)
  • == (equals, if 5 == 5 -> True)
  • in (contains, if "shop" in "shopify" -> True)
  • {{ text_field }}.startswith() (text starts with characters, "hello".startswith("he") -> True)
  • {{ text_field }}.endswith() (text ends with characters, "hello".endswith("h") -> False)
  • {{ text_field }}.isdigit() (text only contains numbers, "090210".isdigit() -> True, "R2D2-V3".isdigit() -> False)

Note: Conditional expressions should always have a final "else" statement (the final else can output just an empty value like: else "").

EXAMPLES

I want to categorize my orders based on total_price.

"High" if {{ total_price }} >= 1000 else "Medium" if {{ total_price }} >= 100 else "Low"

This will assign the value "High" if the order's total_price is greater than or equal to 1000, "Medium" between 100-1000, and "Low" if below 100.

I want to export the text "Investigate" if the tags field contains the tag "High Risk", and export "OK" otherwise.

"Investigate" if "High Risk" in to_list({{ tags }}) else "OK"

This formula will convert the comma-separated list of tags into a list/array object first and then check if one of the tags is "High Risk".  If True, it will export "Investigate", otherwise export "OK".

I want an additional field for the destination's region.

"North America" if {{ shipping_address.country_code }} in ["US", "CA", "MX"] else "Other"

If the shipping address' country code is US, CA, or MX, assign the value "North America", otherwise, use "Other". 

I want to check if a string of characters exists in a longer string.

"yes" if "XYZ" in {{ variants.sku }} else "no"

For example, if the value of variants.sku is "123XYZ456", the formula will output "yes".  It will output "yes" as long as the "XYZ" string exists anywhere in the SKU, such as "XYZ1124831" or "23DDSAXYZ123".

Export a blank value if the zip code contains non-numeric characters.  Otherwise, export as is if it only contains numbers.

"" if not {{ shipping_address.zip }}.isdigit() else {{ shipping_address.zip }}

I want to export the variant's image URL if it exists, otherwise just export the parent product's image URL.

{{ variants.image_src }} if {{ variants.image_src }} != "" else {{ image.src }}

This will export the variant's image URL if it exists (i.e. value is not blank/empty) and will export the product's image URL otherwise.

I want an additional field to set an order's priority based on price or weight.

"High" if {{ total_price }} > 500 or {{ total_weight }} > 1000 else "Normal"

If the order's total price is above 500 or if the total weight is over 1000, mark this order as high priority.

I want a column indicating the order is a high priority depending on the shipping address state/province.

"High Priority" if ({{ shipping_address.province_code }} == "NY" or {{ shipping_address.province_code }} == "NJ") else ""

Display "High Priority" if the shipping address state/province code is either NY or NJ.  Otherwise, just leave it blank.

I want to export the value 1111111111 if the Shipping Address Phone Number is blank, otherwise export the field's actual value.

"1111111111" if {{ shipping_address.phone }} == "" else {{ shipping_address.phone }}

Related Articles:


App: EZ Exporter

Tags: advanced features