This article helps you:
Understand how derived properties can benefit your analysis
Review the functions and operators that can be used when creating your derived properties
You may want to run analyses based on properties that weren't sent to Amplitude. Amplitude Data’s derived properties allow you to create new event and user properties retroactively, based on functions and operators that you can apply across multiple existing properties. These don't affect your raw data and Amplitude computes them on the fly.
For example, you may want to create a chart that groups by whether an item added to a shopping cart is eligible for a discount. In that case, you could create a derived property whose value is a boolean based on whether the price exceeds a certain amount.
This feature is available to users on Enterprise plans only. See the pricing page for more details.
You must be in your project's main
branch to create a derived property.
To create a derived property, follow these steps:
As long as the formula you entered is valid, you can test the results in the space below the formula editor. Do this by selecting existing values for properties used in the formula, or test out any free-form values. You can do this from either the Create/Edit modal or from the side panel for a saved derived property.
Taking our previous referrer URL example, you can write a formula using string operators that looks like this:
SPLIT(PROPERTY('referrer_url','event'), "/", 2)
This formula converts a value like "https://www.google.com/search?q=amplitude" into the value "www.google.com." But what if you want to strip this down even further, to just "google"? You can achieve this by wrapping the result of a SPLIT function inside another SPLIT function. The resulting formula would look like this:
SPLIT(SPLIT(PROPERTY('referrer_url','event'), "/", 2), ".", 1)
Amplitude also supports math operators. Let’s say you have events that contain subtotal and tip properties, and you want to run some analyses based on the total amount. You can use this formula:
SUM(PROPERTY('subtotal','event'), PROPERTY('tip','event'))
Maybe you're also interested in knowing how many orders you would have given discounts to if the total order size was over $50. This formula tells you whether a particular order would receive a discount:
IF(SUM(PROPERTY('subtotal','event'), PROPERTY('tip','event')) >= 50, 'true')
Queries using derived properties may experience longer query times depending on the complexity of the formulas. There is also a limit of up to 10 property references per derived property.
Function | Description | Example | Result |
---|---|---|---|
REGEXEXTRACT (text_property, regular_expression) |
Extracts substrings matching the regular expression. | REGEXEXTRACT("shirt-150", "[0-9]+") |
150 |
REGEXREPLACE (text_property, regular_expression, replacement_text) |
Replaces the property's values with text matching the regular expression with replacement text. | REGEXREPLACE("en-US", "-.*", "") |
en |
CONCAT(property1, property2) |
Concatenates a property with another property or text value. | CONCAT("firstName", "lastName") |
firstName lastName |
LOWERCASE (text_property) |
Lower cases all characters in property's values. | LOWERCASE("John") |
john |
UPPERCASE (text_property) |
Upper cases all characters in property's values. | UPPERCASE("John") |
JOHN |
SPLIT (property, separator, [index]) |
Split a property based on a delimiter and return an array of split elements. Takes an optional index that returns the element at that index. | SPLIT("a_b_c", "_") <br/>SPLIT("john@example.com", "@", 0) |
["a", "b", "c"] <br />"john" |
REMOVE (property, text) |
Remove all occurrence of text in property. | REMOVE("en-US", "en-") |
US |
EXTRACT_FROM_DICT (property, text) |
Extract a value from a dictionary string based on a specific key. | EXTRACT_FROM_DICT("{'id': 1, 'name': 'John', 'country': 'US'}", "name") |
John |
Function | Description | Example | Result |
---|---|---|---|
SUM(num_property1, num_property2) |
Adds a property with other properties or with numbers. Equivalent to the + operator. Use ADD as an alias. |
SUM(subtotal, tip) >>> SUM(10, 2) |
12 |
MINUS(num_property1, num_property2) |
Subtracts a property with other properties or with numbers. Equivalent to the - operator. Use SUBTRACT as an alias. |
MINUS(total, tip) >>> MINUS(12, 2) |
10 |
MULTIPLY (num_property1, num_property2) |
Multiplies a property with other properties and/or with numbers. Equivalent to the * operator. |
MULTIPLY(price, quantity) >>> MULTIPLY(2.50, 4) |
10 |
DIVIDE(numerator, denominator) |
Divides a property by another property or number. Equivalent to the / operator. |
DIVIDE(calorie_intake, calorie_goal) >>> DIVID(1000, 2000) |
0.5 |
POWER(num_property, exponent) |
Takes the property's values to the exponent power. | POWER(property, 3) >>> POWER(2, 3) |
8 |
MIN(num_property1, num_property_2) |
Returns the minimum value between two numbers. | MIN(5, 10) |
5 |
MAX(num_property1, num_property_2) |
Returns the maximum value between two numbers. | MAX(5, 10) |
10 |
CEIL(num_property) |
Rounds up to the nearest integer. | CEIL(3.8) |
4.0 |
FLOOR(num_property) |
Rounds down to the nearest integer. | FLOOR(3.8) |
3.0 |
Function | Description | Example | Result |
---|---|---|---|
EXTRACT_FROM_DICT (property, text) |
Extract a value from a dictionary string based on a specific key. | EXTRACT_FROM_DICT("{'id': 1, 'name': 'John', 'country': 'US'}", "name") |
John |
Amplitude requires all Unix timestamps to be in milliseconds.
Function | Description | Example | Result |
---|---|---|---|
DATE_TO_LONG (date_property) |
Convert date into Unix timestamp | DATE_TO_LONG("2020-12-01") |
1606780800000 |
TIME_TO_LONG (time_property) |
Convert date time (YYYY-MM-dd[T]HH:mm:ss) into Unix timestamp | TIME_TO_LONG("2020-12-01 12:00:00") |
1606780800000 |
LONG_TO_TIME (number_property) |
Convert Unix timestamp into date-time | LONG_TO_TIME (1606780800000) |
2020-12-01 12:00:00 |
LONG_TO_DATE (number_property) |
Convert Unix timestamp into date | LONG_TO_DATE (1606780800000) |
2020-12-01 |
DATE_TIME_FORMATTER (datetime_property, old_format, new_format) |
Convert format of a datetime property to a new format. See Java SimpleDateFormat for more details. | DATE_TIME_FORMATTER ("05.01.2021 12:00:00:000", "MM.dd.yyyy hh:mm:ss:SSS", "yyyy/MM/dd") |
2021/05/01 |
TODAY() |
Current day represented as a long in epoch time in UTC. | TODAY() - start_date_in_ms >>> 1609459200000 - 1577836800000 |
31622400000 |
EVENT_HOUR_OF_DAY() |
Get hour of day (0-23) from the event's timestamp. | EVENT_HOUR_OF_DAY() |
10 |
EVENT_DAY_OF_WEEK() |
Get day of week from the event's timestamp as string. For example, Monday. | EVENT_DAY_OF_WEEK() |
Monday |
DATE_TIME_FORMATTER (datetime_property, old_format, new_format) |
Convert format of a datetime property to a new format. See Java SimpleDateFormat for more details. | DATE_TIME_FORMATTER ("05.01.2021 12:00:00:000", "MM.dd.yyyy hh:mm:ss:SSS", "yyyy/MM/dd") |
2021/05/01 |
When performing computations on derived properties created from array properties, Amplitude assumes that only the first child is an array property, and only considers the first value of the other children, even if they're also array properties.
Here are some illustrative examples:
1Example 12 propA = [1,2,3], propB = [a,b,c]3 CONCAT(propA, propB) = [1a, 2a, 3a]4Example 25 propA = [1, 2, 3], propB = [a]6 CONCAT(propA, propB) = [1a, 2a, 3a]7Example 38 propA = [1], propB = [a, b, c]9 CONCAT(propA, propB) = [1a]
Function | Description | Example | Result |
---|---|---|---|
ITEM_COUNT (property) |
Length of array property; defaults to 1 for non-arrayed properties. | ITEM_COUNT(products) |
3 |
GREATEST(property) |
Get max value of the array. | GREATEST(prices) |
10 |
LEAST(property) |
Get min value of the array. | LEAST(prices) |
2 |
COALESCE(property) |
Get the first non-null value of the array | COALESCE(locations) |
'California' |
When you select a property from the Insert Property dropdown, Amplitude inserts a property function referencing it directly into the editor for you. You can also manually insert this function wherever you want to reference a different Amplitude property.
These functions can only be used within another function.
Function | Description | Example | Result |
---|---|---|---|
PROPERTY(property_name, property_type) |
Reference to property within Amplitude. Possible property types: "user", "event", "derived", "lookup", "group" | PROPERTY("first name","user") |
A reference to the user property "first name" in your project. This is how derived properties communicate with Amplitude’s query service. |
PROPERTY(property_name, "group", group_type) |
Reference to group property within Amplitude. Group type is required for group properties. | PROPERTY("name","group", "business") |
A reference to the group property "name" in the group type "business" within your project. This is how derived properties communicate with Amplitude’s query service. |
Operator | Description | Example |
---|---|---|
IF(logical_expression, value_if_true, value_if_false) |
Returns value_if_true if logical_expression is true, otherwise returns value_if_false . |
IF(property == "(none)", "Property wasn't set", "Property was set") |
AND(logical_expression_1, logical_expression_2) |
Returns True if both logical expressions are true, false otherwise. | AND(is_subscribed == "true", has_valid_promo == "true") |
OR(logical_expression_1, logical_expression_2) |
Returns True if any logical expression is true, false otherwise. | OR(has_email == "true", has_phone == "true") |
SWITCH(expression, case_1, value_1, [case_2, value_2 ...], [default]) |
Evaluates an expression and returns values based on defined cases. Returns a default value if no cases are met if defined, otherwise null. | SWITCH(tier, "gold", 2, "silver", 2, "bronze", 1, 0) |
Operator | Example |
---|---|
== |
action == "purchase" |
!= |
item_count != 0 |
contains |
email contains "@gmail.com" |
does not contain |
title does not contain "officer" |
< , <= , > , >= |
duration >= 60 |
glob match |
url glob match "https://www.google.*/*" |
glob does not match |
query glob does not match "*/query=*" |
has prefix |
title has prefix "sir" |
Set literals ("apple", "orange") must appear on the right hand side of the operator.
Operator | Example |
---|---|
== |
IF(product == ("apple","orange"), "true", "false") product = "apple", Returns "true" |
!= |
IF(product != ("apple","orange"), "true", "false") product = "banana", Returns "true" |
This section provides a description of several common use cases for derived properties formulas.
1CEIL(2 DIVIDE(3 MINUS(4 PROPERTY('server_upload_time', 'amplitude_user'),5 TIME_TO_LONG(PROPERTY('Created At', 'user'))6 ),7 864000008 )9)
Use this when tracking a user property with a date-time data type, and you want to calculate the age of that user (in other words, how long that user has existed in your system) since the time of the event that triggered when this user property was set.
1DIVIDE( 2 SUBTRACTION( 3 DATE_TO_LONG( 4 PROPERTY( 5 'Subscription Start Date', 'user' 6 ) 7 ), 8 DATE_TO_LONG( 9 PROPERTY(10 'Subscription End Date', 'user'11 )12 )13 ),14 8640000015)
Sample output:
In the derived property above, the properties end_date
and start_date
are converted into UNIX timestamps, so that Amplitude can calculate the difference between them. That result is then divided by 86400000, which is the number of milliseconds in one day.
This output is a double type (for example. 2.0).
1IF( 2 DATE_TIME_FORMATTER( 3 PROPERTY( 4 'publishDate', 5 'event' 6 ), 7 "yyyy-MM-dd'T'HH:mm:ssX", 8 'yyyy-MM-dd' 9 )10 contains '-',11 DATE_TIME_FORMATTER(12 PROPERTY(13 'publishDate',14 'event'15 ),16 "yyyy-MM-dd'T'HH:mm:ssX",17 'yyyy-MM-dd'18 ),19 IF(20 DATE_TIME_FORMATTER(21 PROPERTY(22 'publishDate',23 'event'24 ),25 "yyyy-MM-dd HH:mm:ss",26 'yyyy-MM-dd'27 )28 contains '-',29 DATE_TIME_FORMATTER(30 PROPERTY(31 'publishDate',32 'event'33 ),34 "yyyy-MM-dd HH:mm:ss",35 'yyyy-MM-dd'36 ),37 DATE_TIME_FORMATTER(38 PROPERTY(39 'publishDate',40 'event'41 ),42 "yyyy-MM-dd",43 'yyyy-MM-dd'44 )45 )46)47IF(48 DATE_TIME_FORMATTER(49 $60,50 "yyyy-MM-dd'T'HH:mm:ssX",51 'yyyy-MM-dd'52 )53 contains '-',54 DATE_TIME_FORMATTER(55 $61,56 "yyyy-MM-dd'T'HH:mm:ssX",57 'yyyy-MM-dd'58 ),59 IF(60 DATE_TIME_FORMATTER(61 $72,62 "yyyy-MM-dd HH:mm:ss",63 'yyyy-MM-dd'64 ) contains '-',65 DATE_TIME_FORMATTER(66 $73 ,67 "yyyy-MM-dd HH:mm:ss",68 'yyyy-MM-dd'69 ),70 DATE_TIME_FORMATTER(71 $76 ,72 "yyyy-MM-dd",73 'yyyy-MM-dd'74 )75 )76)
Sample output:
One way to format dates to Standard Date Format is to use a series of IF statements. Make sure the higher specificity conditional comes first. Replace the $<number>
here with the actual properties.
1CONCAT(2 REGEXEXTRACT(3 PROPERTY(4 'Subscription Start Date',5 'user'6 ),7 'dddd-dd'8 ), "-01"9)
In this example, the derived property pulls the sign-up month and year from a property that contains a more detailed value, and append the "-01" to set it to the beginning of the month. Use the REGEXEXTRACT()
to pull the year and month from the value, and use CONCAT()
to append the "-01". Replace the $<number>
here with the actual properties.
1IF( 2 OR( 3 REGEXEXTRACT( 4 PROPERTY( 5 "package", 6 "event" 7 ), 8 'Casual' 9 ) =='Casual',10 REGEXEXTRACT(11 PROPERTY(12 "package",13 "event"14 ),15 '1 Job Posting'16 )=='1 Job Posting',17 REGEXEXTRACT(18 PROPERTY(19 "package",20 "event"21 ),22 '1 Basic'23 )=='1 Basic'24 ),25 'Casual',26 'False'27)
Sample output:
To replace multiple property values, use REGEXEXTRACT()
to pull the string in the property, and use OR statements inside an IF statement to see if the value pulled from the properties contains any of the values you wish to replace. In this example, if the property value matches any of the values specified, it replaces the value with Casual
. Otherwise, it replaces the property with False
. Replace the $<number>
here with the actual properties.
Convert the string to an array format by using SPLIT:
1SPLIT(2PROPERTY('color', 'event'),3','4)
Sample output:
The property color was ingested as a string into Amplitude "Red, Green, Blue". After using SPLIT, the resulting value is [Red, Green, Blue]
.
Use the above derived property within a new derived property that uses ITEM_COUNT
.
1ITEM_COUNT(2PROPERTY("Transform into Array", "derived")3)
Sample output:
Now the underlying data being used is an array. ITEM_COUNT
counts the number of items that make up the array.
Thanks for your feedback!
June 18th, 2024
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.