Manipulate data in your workflows with advanced calculation functions
Calculations allow you to manipulate and transform data in your workflows. Use them in automations, layouts, and data processing to create dynamic, intelligent applications.
Calculates the total sum of values in a related field.Syntax:SUM(related_field)Business Example:
Copy
Ask AI
// Total revenue from all ordersSUM(ORDERS."Amount")// Total hours worked by employeeSUM(TIMESHEETS."Hours")// Total inventory valueSUM(PRODUCTS."StockLevel" * PRODUCTS."UnitCost")// Customer lifetime valueSUM(CUSTOMER_ORDERS."Amount")
Arguments:
related_field: Field from related records to sum
This function only works with related fields, not individual values. For adding individual values, use the ’+’ operator.
AVERAGE - Calculate mean value
Returns the numerical average of values in a related field.Syntax:AVERAGE(related_field)Business Example:
Copy
Ask AI
// Average customer ratingAVERAGE(REVIEWS."Rating")// Average order valueAVERAGE(ORDERS."Amount")// Average employee salary by departmentAVERAGE(EMPLOYEES."Salary")// Average project completion timeAVERAGE(PROJECTS."CompletionDays")
Arguments:
related_field: Field from related records to average
Blank values are automatically excluded from the calculation.
COUNT - Count related records
Counts the number of non-null values in a related field.Syntax:COUNT(related_field)Business Example:
Copy
Ask AI
// Number of orders placedCOUNT(ORDERS."ID")// Number of completed tasksCOUNT(TASKS."CompletedDate")// Number of active customersCOUNT(CUSTOMERS."LastLoginDate")// Number of products in stockCOUNT(PRODUCTS."StockLevel")
Arguments:
related_field: Field from related records to count
Use the ID field to count total records, or use a specific field to count only non-null values.
COUNTIF - Count records meeting criteria
Counts non-null values in a related field that meet a specified condition.Syntax:COUNTIF(related_field, criterion)Business Example:
related_field: Field from related records to count
criterion: Condition to meet (supports comparison operators)
Alternative syntax: SUM(IF(RELATED."Field" = 'Paid', 1, 0))
COUNTUNIQUE - Count unique values
Counts the number of unique values in a related field.Syntax:COUNTUNIQUE(related_field)Business Example:
Copy
Ask AI
// Number of unique customersCOUNTUNIQUE(ORDERS."CustomerID")// Number of different product categoriesCOUNTUNIQUE(PRODUCTS."Category")// Number of unique sales repsCOUNTUNIQUE(DEALS."SalesRep")// Number of unique support ticket typesCOUNTUNIQUE(TICKETS."Type")
Arguments:
related_field: Field from related records to count unique values
Null values are excluded from the count.
MAX - Find maximum value
Returns the maximum value from a given set of values.Syntax:MAX(value1, value2, ...)Business Example:
Copy
Ask AI
// Highest of three scoresMAX(PERFORMANCE."Q1Score", PERFORMANCE."Q2Score", PERFORMANCE."Q3Score")// Maximum shipping cost between optionsMAX(SHIPPING."Standard", SHIPPING."Express", SHIPPING."Overnight")// Latest date from multiple fieldsMAX(CUSTOMER."LastPurchase", CUSTOMER."LastContact", CUSTOMER."LastLogin")
Arguments:
value1, value2, ...: Values to compare
Blank values are ignored. For aggregate calculations, use MAX_AGGREGATE.
MAX_AGGREGATE - Find maximum in related field
Finds the maximum value from a related field or calculation.Syntax:MAX_AGGREGATE(related_field)Business Example:
Copy
Ask AI
// Highest order amountMAX_AGGREGATE(ORDERS."Amount")// Best employee performance scoreMAX_AGGREGATE(EMPLOYEES."PerformanceScore")// Peak sales monthMAX_AGGREGATE(MONTHLY_SALES."Revenue")// Highest customer satisfaction ratingMAX_AGGREGATE(SURVEYS."SatisfactionScore")
Arguments:
related_field: Field from related records to find maximum
This is the aggregate version of MAX for related data.
MIN - Find minimum value
Returns the minimum value from a given set of values.Syntax:MIN(value1, value2, ...)Business Example:
Copy
Ask AI
// Lowest of three pricesMIN(PRICING."Standard", PRICING."Discount", PRICING."Wholesale")// Earliest date from multiple fieldsMIN(PROJECT."StartDate", PROJECT."PlannedStart", PROJECT."ActualStart")// Minimum required inventoryMIN(PRODUCT."SafetyStock", PRODUCT."ReorderPoint", 10)
Arguments:
value1, value2, ...: Values to compare
Blank values are ignored. For aggregate calculations, use MIN_AGGREGATE.
MIN_AGGREGATE - Find minimum in related field
Finds the minimum value from a related field or calculation.Syntax:MIN_AGGREGATE(related_field)Business Example:
related_field: Field from related records to find minimum
This is the aggregate version of MIN for related data.
ROUND - Round numbers
Rounds a number to a specified number of decimal places.Syntax:ROUND(number, [decimal_places])Business Example:
Copy
Ask AI
// Round currency to 2 decimal placesROUND(ORDERS."Amount", 2)// Round percentage to whole numberROUND(SALES."GrowthRate" * 100, 0)// Round to nearest thousandROUND(REVENUE."Annual", -3)// Round average ratingROUND(AVERAGE(REVIEWS."Rating"), 1)
Arguments:
number: Number to round
decimal_places: [OPTIONAL] Number of decimal places (default: 0)
Negative decimal_places rounds to left of decimal point (e.g., -1 rounds to tens).
STDEV - Calculate standard deviation
Calculates the standard deviation of a related field.Syntax:STDEV(related_field)Business Example:
Copy
Ask AI
// Variability in order amountsSTDEV(ORDERS."Amount")// Consistency of employee performanceSTDEV(EMPLOYEES."PerformanceScore")// Product rating consistencySTDEV(REVIEWS."Rating")// Sales performance variabilitySTDEV(SALES_REPS."MonthlySales")
Arguments:
related_field: Field from related records to calculate standard deviation
Standard deviation measures how spread out values are from the average.
SUMIF - Sum values meeting criteria
Returns the sum of values in a field that meet a specified condition.Syntax:SUMIF(related_field, criterion)Business Example:
Copy
Ask AI
// Revenue from high-value ordersSUMIF(ORDERS."Amount", '>1000')// Total hours for completed tasksSUMIF(TASKS."Hours", TASKS."Status" = 'Completed')// Revenue from premium customersSUMIF(ORDERS."Amount", CUSTOMERS."Tier" = 'Premium')// Sales from specific regionSUMIF(SALES."Amount", SALES."Region" = 'North')
Arguments:
related_field: Field from related records to sum
criterion: Condition values must meet
Use operators like greater than, less than, greater than or equal to, less than or equal to, and equal to in your criteria.
Returns the current date and time.Syntax:NOW()Business Example:
Copy
Ask AI
// Timestamp for new recordsNOW()// Days since order placedDATEDIF(ORDERS."OrderDate", NOW(), 'D')// Current year for reportingYEAR(NOW())// Age calculationDATEDIF(CUSTOMERS."BirthDate", NOW(), 'Y')
This function takes no arguments and always returns the current moment.
DATE - Create date from components
Returns a date value based on provided year, month, and day.Syntax:DATE(year, month, day)Business Example:
Copy
Ask AI
// Create fiscal year start dateDATE(YEAR(NOW()), 4, 1)// Build date from separate fieldsDATE(ORDERS."Year", ORDERS."Month", ORDERS."Day")// Create quarter end dateDATE(2024, 3, 31)// Generate report dateDATE(REPORTS."ReportYear", REPORTS."ReportMonth", 1)
Arguments:
year: Four-digit year
month: Month (1-12)
day: Day of month (1-31)
Values exceeding normal ranges automatically adjust (e.g., month 13 becomes January of next year).
DATETIME - Create datetime from components
Returns a datetime value in the company’s timezone.Syntax:DATETIME(year, month, day, hour, minute, second)Business Example:
Calculates the difference between two dates in specified units.Syntax:DATEDIF(start_date, end_date, unit)Business Example:
Copy
Ask AI
// Customer ageDATEDIF(CUSTOMERS."BirthDate", NOW(), 'Y')// Days since last purchaseDATEDIF(CUSTOMERS."LastPurchaseDate", NOW(), 'D')// Project duration in monthsDATEDIF(PROJECTS."StartDate", PROJECTS."EndDate", 'M')// Employee tenureDATEDIF(EMPLOYEES."HireDate", NOW(), 'Y')
Arguments:
start_date: Beginning date
end_date: End date
unit: ‘Y’ for years, ‘M’ for months, ‘D’ for days
Returns negative values if start_date is after end_date.
DATETIME_TRUNC - Truncate datetime
Truncates a datetime to a specified unit.Syntax:DATETIME_TRUNC(datetime, unit)Business Example:
Copy
Ask AI
// Start of month for reportingDATETIME_TRUNC(ORDERS."OrderDate", 'MONTH')// Start of day for daily summariesDATETIME_TRUNC(EVENTS."EventTime", 'DAY')// Start of quarterDATETIME_TRUNC(SALES."SaleDate", 'QUARTER')// Start of yearDATETIME_TRUNC(EMPLOYEES."HireDate", 'YEAR')
Arguments:
datetime: Datetime to truncate
unit: YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND
Useful for grouping data by time periods.
DATEVALUE - Convert text to date
Converts text date value into a DATE object.Syntax:DATEVALUE(text_date)Business Example:
Copy
Ask AI
// Convert imported date textDATEVALUE(IMPORTS."DateString")// Parse date from external systemDATEVALUE(EXTERNAL."FormattedDate")// Convert user-entered dateDATEVALUE(FORMS."SubmissionDate")
Arguments:
text_date: Text representation of a date
Returns null if the text cannot be parsed as a date.
DAY - Extract day from date
Returns the day of the month (1-31) from a date.Syntax:DAY(date)Business Example:
Copy
Ask AI
// Extract day for daily reportsDAY(ORDERS."OrderDate")// Get payment dayDAY(INVOICES."DueDate")// Extract birth dayDAY(CUSTOMERS."BirthDate")
Arguments:
date: Date to extract day from
Returns a number between 1 and 31.
MONTH - Extract month from date
Returns the month (1-12) from a date.Syntax:MONTH(date)Business Example:
Copy
Ask AI
// Extract month for monthly reportsMONTH(ORDERS."OrderDate")// Get birth monthMONTH(CUSTOMERS."BirthDate")// Extract fiscal monthMONTH(TRANSACTIONS."TransactionDate")
Arguments:
date: Date to extract month from
Returns a number between 1 (January) and 12 (December).
YEAR - Extract year from date
Returns the year from a date.Syntax:YEAR(date)Business Example:
Copy
Ask AI
// Extract year for annual reportsYEAR(ORDERS."OrderDate")// Get hire yearYEAR(EMPLOYEES."HireDate")// Extract birth yearYEAR(CUSTOMERS."BirthDate")
Arguments:
date: Date to extract year from
Returns a four-digit year number.
HOUR - Extract hour from datetime
Returns the hour (0-23) from a datetime.Syntax:HOUR(datetime)Business Example:
Copy
Ask AI
// Extract hour for time-based analysisHOUR(ORDERS."OrderTime")// Get meeting hourHOUR(MEETINGS."StartTime")// Extract login hourHOUR(USERS."LastLogin")
Arguments:
datetime: Datetime to extract hour from
Returns a number between 0 (midnight) and 23 (11 PM).
MINUTE - Extract minute from datetime
Returns the minute (0-59) from a datetime.Syntax:MINUTE(datetime)Business Example:
Copy
Ask AI
// Extract minute for precise timingMINUTE(MEETINGS."StartTime")// Get appointment minuteMINUTE(APPOINTMENTS."ScheduledTime")// Extract timestamp minuteMINUTE(EVENTS."EventTime")
Arguments:
datetime: Datetime to extract minute from
Returns a number between 0 and 59.
SECOND - Extract second from datetime
Returns the second (0-59) from a datetime.Syntax:SECOND(datetime)Business Example:
Copy
Ask AI
// Extract second for precise timingSECOND(TRANSACTIONS."Timestamp")// Get event secondSECOND(EVENTS."EventTime")// Extract log secondSECOND(LOGS."LogTime")
Arguments:
datetime: Datetime to extract second from
Returns a number between 0 and 59.
WEEKDAY - Get day of week
Returns the day of the week (1-7) for a date.Syntax:WEEKDAY(date, [type])Business Example:
Copy
Ask AI
// Check if order was placed on weekendWEEKDAY(ORDERS."OrderDate") = 1 OR WEEKDAY(ORDERS."OrderDate") = 7// Get weekday for schedulingWEEKDAY(MEETINGS."MeetingDate", 2)// Analyze sales by day of weekWEEKDAY(SALES."SaleDate")
Various field types are automatically converted to text for concatenation.
UPPER - Convert to uppercase
Converts text to uppercase letters.Syntax:UPPER(text)Business Example:
Copy
Ask AI
// Standardize product codesUPPER(PRODUCTS."SKU")// Format state abbreviationsUPPER(CUSTOMERS."State")// Consistent department namesUPPER(EMPLOYEES."Department")// Normalize country codesUPPER(ADDRESSES."CountryCode")
Arguments:
text: Text to convert to uppercase
Useful for standardizing data entry and comparisons.
LOWER - Convert to lowercase
Converts text to lowercase letters.Syntax:LOWER(text)Business Example:
Essential for consistent data processing and matching.
LEFT - Extract from start of text
Extracts characters from the beginning of a string.Syntax:LEFT(text, number_of_characters)Business Example:
Copy
Ask AI
// Extract first 3 characters of product codeLEFT(PRODUCTS."SKU", 3)// Get first initialLEFT(CUSTOMERS."FirstName", 1)// Extract area code from phoneLEFT(CUSTOMERS."Phone", 3)// Get first part of order numberLEFT(ORDERS."OrderNumber", 4)
Arguments:
text: String to extract from
number_of_characters: Number of characters to extract
Returns the entire string if requested length exceeds string length.
RIGHT - Extract from end of text
Extracts characters from the end of a string.Syntax:RIGHT(text, number_of_characters)Business Example:
Copy
Ask AI
// Extract last 4 digits of credit cardRIGHT(PAYMENTS."CardNumber", 4)// Get file extensionRIGHT(ATTACHMENTS."FileName", 4)// Extract year from date stringRIGHT(RECORDS."DateString", 4)// Get last part of account numberRIGHT(ACCOUNTS."AccountNumber", 6)
Arguments:
text: String to extract from
number_of_characters: Number of characters to extract
Returns the entire string if requested length exceeds string length.
MID - Extract from middle of text
Extracts substring from specified position.Syntax:MID(text, start_position, number_of_characters)Business Example:
Copy
Ask AI
// Extract middle digits from account numberMID(ACCOUNTS."AccountNumber", 5, 4)// Get month from date string (MM/DD/YYYY)MID(RECORDS."DateString", 4, 2)// Extract product category from codeMID(PRODUCTS."SKU", 3, 2)
Arguments:
text: String to extract from
start_position: Starting position (1-based)
number_of_characters: Number of characters to extract
Position counting starts at 1, not 0.
FIND - Find text position (case-sensitive)
Returns position of first case-sensitive substring match.Syntax:FIND(search_text, text_to_search, [start_position])Business Example:
Copy
Ask AI
// Find @ symbol in emailFIND('@', CUSTOMERS."Email")// Find dash in product codeFIND('-', PRODUCTS."SKU")// Find space in full nameFIND(' ', CUSTOMERS."FullName")
Arguments:
search_text: Text to find
text_to_search: Text to search within
start_position: [OPTIONAL] Starting position for search
Returns 0 if text not found. Case-sensitive search.
SEARCH - Find text position (case-insensitive)
Returns position of first case-insensitive substring match.Syntax:SEARCH(search_text, text_to_search, [start_position])Business Example:
Copy
Ask AI
// Find 'premium' in product name (any case)SEARCH('premium', PRODUCTS."Name")// Find 'manager' in job titleSEARCH('manager', EMPLOYEES."JobTitle")// Find 'urgent' in support ticketSEARCH('urgent', TICKETS."Subject")
Arguments:
search_text: Text to find
text_to_search: Text to search within
start_position: [OPTIONAL] Starting position for search
Returns 0 if text not found. Case-insensitive search.
SUBSTITUTE - Replace text
Replaces text occurrences in a string.Syntax:SUBSTITUTE(text, old_text, new_text)Business Example:
Copy
Ask AI
// Replace dashes with spaces in product codesSUBSTITUTE(PRODUCTS."SKU", '-', ' ')// Replace old company name in addressesSUBSTITUTE(CUSTOMERS."Address", 'Old Corp', 'New Corp')// Clean phone number formattingSUBSTITUTE(CUSTOMERS."Phone", '(', '')
Arguments:
text: Original text
old_text: Text to replace
new_text: Replacement text
Replaces ALL occurrences of old_text with new_text.
TRIM - Remove extra spaces
Removes leading and trailing spaces from text.Syntax:TRIM(text)Business Example:
Copy
Ask AI
// Clean up imported customer namesTRIM(CUSTOMERS."Name")// Remove spaces from product codesTRIM(PRODUCTS."SKU")// Clean email addressesTRIM(CUSTOMERS."Email")// Clean up form inputTRIM(FORMS."UserInput")
Arguments:
text: Text to trim
Essential for cleaning up data entry and imports.
LEN - Get text length
Returns the number of characters in a string.Syntax:LEN(text)Business Example:
Concatenates multiple related strings with a delimiter.Syntax:STRING_AGG(related_field, delimiter, [ORDER BY field])Business Example:
Copy
Ask AI
// List all order itemsSTRING_AGG(ORDER_ITEMS."ProductName", ', ')// Create skill list for employeeSTRING_AGG(EMPLOYEE_SKILLS."SkillName", ', ')// List customer tagsSTRING_AGG(CUSTOMER_TAGS."TagName", ', ' ORDER BY CUSTOMER_TAGS."TagName")
Arguments:
related_field: Field from related records to concatenate
delimiter: Text to put between each value
ORDER BY field: [OPTIONAL] Field to sort by before concatenating
Great for creating comma-separated lists from related data.
STRING_AGG_UNIQUE - Concatenate unique values
Concatenates unique values from a related field.Syntax:STRING_AGG_UNIQUE(related_field, delimiter)Business Example:
Copy
Ask AI
// List unique product categoriesSTRING_AGG_UNIQUE(ORDER_ITEMS."Category", ', ')// List unique customer locationsSTRING_AGG_UNIQUE(CUSTOMERS."City", ', ')// List unique skillsSTRING_AGG_UNIQUE(EMPLOYEE_SKILLS."SkillName", ', ')
Arguments:
related_field: Field from related records to concatenate
delimiter: Text to put between each value
Automatically removes duplicates before concatenating.
SPLIT - Split text into array
Splits a string into an array using a delimiter.Syntax:SPLIT(text, delimiter)Business Example:
Copy
Ask AI
// Split full name into partsSPLIT(CUSTOMERS."FullName", ' ')// Split tags by commaSPLIT(PRODUCTS."Tags", ',')// Split address by commaSPLIT(CUSTOMERS."Address", ',')
Arguments:
text: String to split
delimiter: Character or string to split on
Returns an array of substrings. Empty delimiter splits into individual characters.
TEXT - Convert to text
Converts numbers or dates to text format.Syntax:TEXT(value)Business Example:
Copy
Ask AI
// Convert order amount to textTEXT(ORDERS."Amount")// Convert date to textTEXT(ORDERS."OrderDate")// Convert ID to text for concatenationTEXT(CUSTOMERS."ID")
Arguments:
value: Number or date to convert
Useful when you need to treat numbers as text for concatenation.
VALUE - Convert text to number
Converts text to a number.Syntax:VALUE(text)Business Example:
Copy
Ask AI
// Convert text amount to numberVALUE(IMPORTS."AmountText")// Convert text quantity to numberVALUE(FORMS."QuantityInput")// Convert text ID to numberVALUE(EXTERNAL."IDString")
Arguments:
text: Text to convert to number
Returns blank if text cannot be converted to a number.
REP - Repeat text
Repeats a string a specified number of times.Syntax:REP(text, number_of_times)Business Example:
Returns the Boolean value TRUE.Syntax:TRUE()Business Example:
Copy
Ask AI
// Set default active statusTRUE()// Use in conditional logicIF(CUSTOMERS."Status" = 'Active', TRUE(), FALSE())// Initialize flagsTRUE()
Useful for setting boolean field values and conditional logic.
FALSE - Boolean FALSE
Returns the Boolean value FALSE.Syntax:FALSE()Business Example:
Copy
Ask AI
// Set default inactive statusFALSE()// Use in conditional logicIF(ORDERS."Amount" > 0, TRUE(), FALSE())// Initialize flagsFALSE()
Useful for setting boolean field values and conditional logic.
BLANK - Return blank value
Returns a blank/null value.Syntax:BLANK()Business Example:
Copy
Ask AI
// Clear a field conditionallyIF(ORDERS."Status" = 'Cancelled', BLANK(), ORDERS."ShipDate")// Set default empty valueBLANK()// Use in conditional assignmentsIF(CUSTOMERS."Type" = 'Guest', BLANK(), CUSTOMERS."LoyaltyPoints")
Represents the absence of data, different from empty string.
ISBLANK - Test if blank
Tests if a value is blank/null.Syntax:ISBLANK(value)Business Example:
Copy
Ask AI
// Check if customer has phone numberISBLANK(CUSTOMERS."Phone")// Validate required fieldsISBLANK(ORDERS."ShippingAddress")// Check for missing dataISBLANK(PRODUCTS."Description")// Conditional logic based on blank valuesIF(ISBLANK(CUSTOMERS."Email"), 'No Email', 'Has Email')
Arguments:
value: Value to test for blankness
Returns TRUE if value is blank, FALSE if it contains data. Empty string (”) is NOT blank.
UUID - Generate unique ID
Generates a random UUID (Universally Unique Identifier).Syntax:UUID()Business Example:
Problem: Your calculation returns blank instead of expected values.Causes & Solutions:
Blank input data: Check that referenced fields contain data
Invalid field references: Ensure field names are correct and properly quoted
Type mismatches: Verify you’re using the right function for your data type
Example Fix:
Copy
Ask AI
// Instead of this (might return blank):AVERAGE(ORDERS."Amount")// Try this (handles blanks better):IF(COUNT(ORDERS."Amount") > 0, AVERAGE(ORDERS."Amount"), 0)
Prevention:
Always test with sample data
Use ISBLANK() to check for missing data
Validate field names match exactly
Common Error: Function Not Working with Current Record
Problem: Functions like SUM, COUNT, AVERAGE don’t work with fields from the current record.Solution: These functions only work with related fields. For current record calculations, use operators:
Copy
Ask AI
// Wrong - won't work:SUM(CURRENT."Field1", CURRENT."Field2")// Right - use operators:CURRENT."Field1" + CURRENT."Field2"// Right - for related data:SUM(RELATED_RECORDS."Field")
Key Point: Aggregate functions (SUM, COUNT, AVERAGE, etc.) are designed for related data, not individual field operations.
Common Error: Date Calculation Issues
Problem: Date calculations returning unexpected results.Common Fixes:
Text dates: Use DATEVALUE() to convert text to proper dates
// If date is stored as text:DATEDIF(DATEVALUE(CUSTOMERS."SignupDate"), NOW(), 'D')// For consistent date creation:DATE(YEAR(NOW()), MONTH(NOW()), 1)// Handle blank dates:IF(ISBLANK(ORDERS."ShipDate"), 'Not Shipped', DATEDIF(ORDERS."OrderDate", ORDERS."ShipDate", 'D'))
Common Error: Text Function Confusion
Problem: FIND vs SEARCH, UPPER vs LOWER, concatenation issues.Solutions:
Problem: Field references not working, getting ‘field not found’ errors.Solutions:
Check field names: Must match exactly (case-sensitive)
Use proper syntax: HANDLE.”FieldName” format
Verify relationships: Ensure fields are properly related
Example Fixes:
Copy
Ask AI
// Correct field reference:CUSTOMERS."FirstName"// Wrong - missing quotes:CUSTOMERS.FirstName// Wrong - incorrect case:CUSTOMERS."firstname"// For related fields:RELATED_CUSTOMERS."FirstName"
Performance Issues
Problem: Calculations running slowly or timing out.Solutions:
Simplify complex calculations: Break into smaller parts
Avoid nested functions: Use intermediate calculations
Check data volumes: Large datasets may need optimization
Example Optimization:
Copy
Ask AI
// Instead of nested complexity:IF(AND(CUSTOMERS."Status" = 'Active', DATEDIF(CUSTOMERS."LastPurchase", NOW(), 'D') < 30), 'Recent', 'Old')// Break it down:// Step 1: Days since purchaseDATEDIF(CUSTOMERS."LastPurchase", NOW(), 'D')// Step 2: Use result in simpler IFIF(PREVIOUS_CALC < 30, 'Recent', 'Old')