For the complete documentation index, see llms.txt. This page is also available as Markdown.

Custom formula

What is a custom formula?

A custom formula is a feature that lets you build your own calculations when analyzing data in Laplace. Much like formulas in Excel or Google Sheets, you can combine existing measures and dimensions to create new metrics.

What you can do with custom formulas

  1. Ratio calculations: Key metrics such as conversion rate, average order value and cost per click

  2. Goal management: Goal attainment rate, actual vs. target, progress tracking

  3. Conditional analysis: Grading and segmentation

  4. String handling: Cleaning, parsing, joining and converting data

  5. Date operations: Extracting year · month · day · week number · weekday · quarter

  6. Compound calculations: Advanced metrics such as ROAS, ROI and net profit margin

Create a custom formula

  1. On the Data tab of the settings panel on the right of the chart editor, choose a data source and measures first.

  2. Under Data tab › Custom formula, click New formula.

  3. In Formula name, enter the name to show in the table and the measure list. (e.g. ROAS)

  4. Enter measures and functions in Expression. Hover over a function or Example in the list on the left to see a description; click it to insert it into the expression.

  5. Under Number format, choose one of Number · Currency · Ratio · Text, then click Save.

    Custom formula editor

Saved formulas are added to the table automatically and also appear in the measure list on the Chart tab, so you can chart them. You can Edit formula or Duplicate a formula from the Custom formula list.

How it works

Custom formulas work in the following order:

  1. Enter an expression

  1. Syntax check Checks parentheses, quotes and function names, and whether the referenced columns exist in the measures and dimensions currently selected

  2. Calculation Queries data with the selected measures and dimensions, then applies the expression to each row of the result to create a new column

  3. Display results Shows the calculated values on the dashboard

Comparison with Excel

Item
Excel/spreadsheets
Laplace custom formula

Cell reference

A1, B2:B10

'revenue', 'order_count'

Division

=A1/B1

DIVIDE('revenue', 'order_count')

Condition

=IF(A1>100, "High", "Low")

IF('revenue' > 100, "High", "Low")

Text

="Hello " & A1

CONCAT("Hello ", 'product_name')

Key differences

  • Wrap column names in single quotes (`'`): 'revenue'

  • Wrap string values in double quotes (`"`): "Completed"

  • Function names aren't case-sensitive. This document writes them in uppercase: DIVIDE

Basic syntax

1. Column references

'column_name'

The column names in this document ('revenue', 'order_count', etc.) are examples to illustrate the syntax. In a real expression, pick a measure or dimension name from the input's autocomplete and that column's key is inserted wrapped in single quotes. For example, revenue is inserted as 'sales', and when you use several data sources, a source letter is added in front, like 'A__sales'.

2. Number literals

You can't write a negative number directly as -50. Make it with subtraction, like 0 - 50.

3. String literals

Use double quotes.

4. Operator precedence

  1. () Parentheses Calculated first.

  2. * / Multiplication, division

    Calculated before addition/subtraction

  3. + - Addition, subtraction

    Calculated after multiplication/division

  4. > < >= <= Comparison operators

    Compared after arithmetic

Operators

Arithmetic operators

Operator
Description
Example
Result

+

Add

'revenue' + 'cost'

Revenue + cost

-

Subtract

'revenue' - 'cost'

Net profit

*

Multiply

'quantity' * 'unit_price'

Total amount

/

Divide

'revenue' / 'order_count'

Average order value

Comparison operators

Operator
Description
Example

=

Equal to

'status' = "Completed"

<>

Not equal to

'status' <> "Canceled"

>

Greater than

'revenue' > 1000

<

Less than

'revenue' < 1000

>=

Greater than or equal to

'order_count' >= 2

<=

Less than or equal to

'order_count' <= 1

Logical functions

AND and OR are used as functions, not as operators placed between conditions. Writing 'revenue' > 1000 AND 'status' = "Completed" causes an error.

Function
Description
Example

AND

AND(condition1, condition2): both are true

AND('revenue' > 1000, 'status' = "Completed")

OR

OR(condition1, condition2): at least one is true

OR('category' = "Apparel", 'category' = "Accessories")

NOT

NOT(condition): flips true and false

NOT('revenue' > 1000)

You can include up to two conditions. For three or more, nest them like AND(condition1, AND(condition2, condition3)).

Function types

An expression is applied separately to each row of the query result. There are no aggregate functions that combine multiple rows, such as sum · average · count · min · max.

Math functions

Function
Syntax
Description
Example

MULTIPLY

MULTIPLY(a, b)

Multiplication

MULTIPLY('quantity', 'unit_price')

DIVIDE

DIVIDE(a, b)

Division

DIVIDE('revenue', 'order_count')

SUBTRACT

SUBTRACT(a, b)

Subtraction

SUBTRACT('revenue', 'cost')

ABS

ABS(value)

Absolute value

ABS('profit_loss')

FLOOR

FLOOR(value)

Round down

FLOOR('decimal_value')

CEIL

CEIL(value)

Round up

CEIL('decimal_value')

Conditional functions

Function
Syntax
Description
Example

IF

IF(condition, true_value, false_value)

Condition

IF('revenue' > 1000, "Excellent", "Average")

IFS

IFS(cond1, val1, cond2, val2, ...)

Multiple conditions. Rows that match no condition are blank

IFS('revenue' >= 10000, "Top", 'revenue' >= 5000, "Excellent")

COALESCE

COALESCE(val1, val2, ...)

Replace NULL

COALESCE('discount', 0)

NULLIF

NULLIF(val1, val2)

NULL if equal

NULLIF('order_count', 0)

String functions

Function
Syntax
Description
Example

CONCAT

CONCAT(str1, str2, ...)

Join strings

CONCAT('first_name', " ", 'last_name')

UPPER

UPPER(text)

Convert to uppercase

UPPER('product_code')

LOWER

LOWER(text)

Convert to lowercase

LOWER('email')

TRIM

TRIM(text)

Remove spaces

TRIM('address')

LENGTH

LENGTH(text)

String length

LENGTH('product_name')

SUBSTR

SUBSTR(text, start, length)

Substring

SUBSTR('phone', 1, 3)

REPLACE

REPLACE(text, old, new)

Replace text

REPLACE('address', "St.", "Street")

Date/time functions

Function
Syntax
Description
Example

NOW

NOW()

Current time

NOW()

CURRENT_DATE

CURRENT_DATE()

Today's date

CURRENT_DATE()

DATE

DATE(year, month, day)

Create a date

DATE(2024, 1, 15)

YEAR

YEAR(date)

Extract year

YEAR('time_id')

MONTH

MONTH(date)

Extract month

MONTH('time_id')

DAY

DAY(date)

Extract day

DAY('time_id')

WEEK

WEEK(date)

Extract week number

WEEK('time_id')

DAY_OF_WEEK

DAY_OF_WEEK(date)

Weekday (1=Sun, 2=Mon, ..., 7=Sat)

DAY_OF_WEEK('time_id')

QUARTER

QUARTER(date)

Quarter

QUARTER('time_id')

Regex functions

Function
Syntax
Description
Example

REGEXP_EXTRACT

REGEXP_EXTRACT(text, pattern)

Extract with regex

REGEXP_EXTRACT('url', "utm_source=([^&]+)")

REGEXP_REPLACE

REGEXP_REPLACE(text, pattern, replacement)

Replace with regex

REGEXP_REPLACE('phone', "[^0-9]", "")

Type conversion functions

Function
Syntax
Description
Example

CAST

CAST(value, "TYPE")

Type conversion

CAST('amount', "DOUBLE")

Examples

Ratio calculations

Item
Calculation
Syntax
Result

Conversion rate (CVR)

(Orders ÷ clicks) × 100

DIVIDE('order_count' * 100, 'clicks')

5.0%

Average order value (AOV)

Revenue ÷ orders

DIVIDE('revenue', 'order_count')

₩ 50,000

Cost per click (CPC)

Ad spend ÷ clicks

DIVIDE('ad_cost', 'clicks')

₩ 200

ROAS

(Revenue ÷ ad spend) × 100

DIVIDE('revenue' * 100, 'ad_cost')

500%

Goal management

Item
Calculation
Syntax
Result

Goal attainment rate

(Actual revenue ÷ target revenue) × 100

DIVIDE('revenue' * 100, 'target_revenue')

85%

Goal attainment grade

S (130%↑) / A (110%↑) / B (90%↑) / C (90%↓)

IF(DIVIDE('revenue', 'target_revenue') >= 1.3, "Grade S", IF(DIVIDE('revenue', 'target_revenue') >= 1.1, "Grade A", IF(DIVIDE('revenue', 'target_revenue') >= 0.9, "Grade B", "Grade C")))

Grade A

Difference from target

Actual revenue - target revenue

SUBTRACT('revenue', 'target_revenue')

+ ₩ 2,000,000

Required daily revenue

(Target - current) ÷ days remaining

DIVIDE( SUBTRACT('target_revenue', 'current_revenue'), 'days_remaining' )

₩ 1,200,000/day

Customer segmentation

Item
Calculation
Syntax
Result

Customer tiers

Platinum (50K↑) / Gold (20K↑) / Silver (10K↑) / Bronze

IF('revenue' >= 50000, "Platinum", IF('revenue' >= 20000, "Gold", IF('revenue' >= 10000, "Silver", "Bronze")))

Weekend/weekday

Identify weekends by weekday number

IF(OR(DAY_OF_WEEK('time_id') = 1, DAY_OF_WEEK('time_id') = 7), "Weekend", "Weekday")

New/returning customers

Classify customer type by number of orders

IF('order_count' > 1, "Returning", "New")

Age group

35 → "30s"

CONCAT( CAST(FLOOR('age' / 10) * 10, "VARCHAR"), "s" )

Tips and cautions

Recommendations

Cautions

Item
❌ Wrong
✅ Correct

Column reference

revenue or "revenue"

'revenue'

String

'Completed'

"Completed"

Column name typo

'revenu'

'revenue'

Frequently asked questions (FAQ)

Q. My expression doesn't work. What should I do?

Checklist:

  1. Did you use only the functions in this document's function tables?

  2. Did you wrap column names in single quotes? ('revenue')

  3. Did you wrap strings in double quotes? ("Completed")

  4. Are all parentheses closed properly?

Q. Can I reference another expression?

Yes, you can! First create an "Average order value" formula: DIVIDE('revenue', 'order_count') Then reference it in another formula: IF('Average order value' > 50000, "VIP", "Regular") ⚠️ Note: Circular references aren't allowed.

Q. How can I improve formula performance?

Recommendations:

  1. Keep complex regular expressions to a minimum.

  2. Filter to only the data you need.

Ask your dedicated manager

Having trouble using custom formulas?

Contact us through the inquiry page or by email below. Your manager will be happy to help.

💬 Contact us on our website

Email: product@laplacetec.com

Last updated