Skip to main content
Version: 24.3

Formula Help

This article explains how to use Formulas in Agility.

Overview

Formulas are expressions that must contain data columns, and can include constants, functions, and operators.

  • Columns values that come from the data. Their names are enclosed in square brackets, like [ShippedDate]. Depending on their data type, they may be used as text strings, numbers, and date or time values.
  • Constants are simply specific fixed values that you enter into a Formula.
  • Functions return values, usually computations based on columns and constants.
  • Operators do arithmetic and logical comparisons. Logical comparisons must be used with Case statements.

Here are some examples:

[UnitPrice] * [Quantity]

Multiply two data columns, UnitPrice and Quantity, to make an ExtendedPrice column.

[UnitPrice] * .04

Multiply a data column by an constant value to calculate the tax applied to the price.

DateDiff("d", [OrderDate], [ShippedDate] )

Get the number of days from the order to the shipment.

DateDiff("w", [ShippedDate], Now )

Get the number of weekdays since the shipment date.

DateName( dw, ShippedDate )

Return the name of the day of the week of the shipment date.

[LastName] + ', ' + [FirstName]

Concatenate columns and strings together. This might return: Smith, John

Upper( [LastName] + ', ' + [FirstName] )

Convert to upper case. This might return: SMITH, JOHN

Functions

Functions accept some number of values and return a single value.

Function NameDescriptionSyntaxNotes
AbsReturns the absolute value of a number.Abs(number) The absolute value of -5 is 5.
CaseReturns one value or another, depending on if the expression is evaluates to True or False.Case variable When value Then return value Else other value Endvariable has a values that will be compared.
value is something that may be matched in the variable.
return value is returned when the variable and value match.
other value is returned when there are no matches.
For example,
Case [Color]
When 'pink' Then 'red'
When 'amber' Then 'yellow'
Else 'gray'
End
DateReturns the current date.Getdate() 
DateAddAdds or subtracts some interval of time from a date or time.DateAdd(interval, number, date)Interval may be:
yyyy=year
q=quarter
m=month
y=day of year
d=day
w=weekday
ww=week of year
hh=hour
n=minute
s=second
DateDiffComputes the difference between two dates.DateDiff(interval, date1, date2)Interval may be:
yyyy=year
q=quarter
m=month
y=day of year
d=day
w=weekday
ww=week of year
hh=hour
n=minute
s=second
DatePartReturns part of a date.DatePart(interval, date)Interval may be:
yyyy=year
q=quarter
m=month
y=day of year
d=day
w=weekday
ww=week of year
hh=hour
n=minute
s=second
DateSerialCombines date parts together to make a date.Cast(Cast(year AS varchar) + '-' + Cast(month AS varchar) + '-' + Cast(day AS varchar) AS DATETIME) 
DateValueReturns a date from a date string. The function can convert dates from many different formats.Convert(DATETIME, date_string)date_string is a string value which represents a date or date/time.
DayReturns the day of the month. Possible return values are from 1-31.Day(date) 
FormatCurrencyFormat a number value into currency.'$' + Convert(varchar(12), NumericValue, 1) 
FormatDateTimeFormats a date.Convert(varchar, date, 120)"120" is the code that dictates the date format. More codes are available for different formats.
FormatNumberFormats a number.Convert(varchar(12), NumericValue, 1) 
FormatPercentFormats a number as a percentage.Convert(varchar,Convert(Decimal(6,2), number)) + '%' 
HourReturns the hour of the day. Possible return values are 0-23.DatePart(hh, date) 
CaseReturns one value or another, depending on if the expression is evaluates to True or False.Case When Expression Then True Else False EndExpression is a formula that returns True or False.
For example, this would return "Blue", because 1 does not equal 2.
Case When 1=2 Then "Red" Else "Blue" End
InStringReturns the character location where one string is found within another string.CharIndex(expressionToFind ,expressionToSearch [,start_location])Returns the index value if the string is found, else returns 0.
IntReturns the integer portion of a number, removing any decimal places.Round(Floatvalue,0,1)ex. ROUND(150.75, 0) = 151.00
ROUND(150.75, 0, 1) = 150.00
IsDateReturns True if the text is a date.IsDate(text)Return 1 if True, else returns False
IsNumericReturns True if the text is a number.IsNumeric(text)Return 1 if True, else returns False
LowerConverts all characters to lower case.Lower(text) 
LeftReturns the "length" number of characters from the left side of the input text.Left(character_expression, integer_expression) 
LenReturns the number of characters in the text.Len(text) 
LTrimRemoves the space characters from the left side of the text.LTrim(text) 
MidReturns characters from the middle of the text.Substring(text,start,length)"start" is the first character to be returned. The first character is at position 1.
"length" is the number of characters to be returned.
MinuteReturns the minute of the hour. Possible return values are 0-59.DatePart(mi,date) 
MonthReturns the month of the year. Possible return values are 1-12.Month(date) 
MonthNameReturns the name of the month.DateName(month,date) 
NowReturns the current date and time.Getdate() 
ReplaceSearches textSearch for textFind, replacing it with the textReplaceWith value.Replace(string1,string_to_replace,[replacement_string]) 
RightReturns the "length" number of characters from the right side of the input text.Right(str,len) 
RandReturns a random number between 0 and 1.Rand([seed])Seed is an integer expression (tinyint, smallint, or int) that gives the seed value.
This parameter is Optional.
RoundReturns a number rounded to a specified number of decimal places.Round(number,length )ex. ROUND(150.75, 0) = 151.00
ROUND(150.75, 0, 1) = 150.00
RTrimRemoves any space characters from the right side of the text.RTrim(text) 
SecondReturns the second of the minute. Possible values are 0-59.DatePart(ss,date) 
SignReturns -1 if the number is negative. Returns 1 if the number is positive. Returns 0 if the number is 0.Sign(number) 
SpaceReturns text consisting of the number of spaces.Space (number) 
SquareReturns the square of a number.Square(number) 
StringReturns text consisting of the character duplicated the number of times.Replicate(text,count) 
ReverseReturns the text with the characters in reverse order.Reverse(text) 
TimeValueReturns a time value from a time string. The function can convert dates from many different formats.Convert(varchar(8),Convert(datetime,text),108) 
TrimRemoves space characters from both the left and rights sides of the text.LTrim(RTrim(text)) 
UpperConverts all characters to upper case.Upper(text) 
WeekdayReturns the number of the day of the week. Possible return values are 1-7.DatePart(wk,date) 
WeekdayNameReturns the name of the day corresponding to the weekday number.DateName(dw,date) 
YearReturns the number of the year of the specified date.Year(date)

In the Syntax column, parameters in square brackets are optional.

Operators

Operators do arithmetic and logical comparisons

OperatorDescription
-Negation
^Exponentiation: Power( m, n ). Function returns m raised to the nth power.
*Multiplication
/Division
%Modulus: m%n.
+Addition
-Subtraction
+String Concatenation

Analytics grids