You can create custom metrics and attributes to use in your report that help you present your business data just how you want it. To do this, you'll need to learn how to write formulas. Formulas perform comparisons, calculations, and manipulations on your data, and help you evaluate conditions.
For more information about formulas, see Formula writing resources.
Understanding Explore formulas
Formulas are generally constructed with two pieces:
- Metrics and attributes that contain your Zendesk information
- Functions that perform operations on those metrics and attributes
Formulas in Explore are read from left to right, and follow the mathematical order of operations. A formula can contain multiple statements, each containing a combination of metrics, attributes, and functions that are used to define the data you're looking for.
Within a formula, functions, such as IF/THEN, are often contained within parentheses
()
, much like algebra, so that they don't affect the rest of the formula.
If a formula has only one function, parentheses might not be necessary.
Metric and attribute names are contained within brackets []
. Metric and
attribute values, expressed as text strings, are contained in quotation marks, and must
match the values exactly. For example, "End-user" and "end user" are two different values.
(For more on attribute values in formulas, see How do I find an attribute value?) Operators are used to connect
attribute names and values, or to perform additional calculations.
Putting this all together, a simple formula might read as follows:
Creating a formula
Now that you know that an Explore formula is made up of metrics, attributes, and functions, you'll learn how to create the example formula above.
It can be helpful to write down the logic of a formula to help you create it and find the right functions you need. In this case, the formula flow is "If the ticket channel is email, show me the ticket ID." You'll see later that this is very similar to the formula you'll end up with.
To create a formula that displays tickets from the email channel
- In Explore, create a new report or open an existing report for editing.
- Open the calculations menu (
).
Important: If two editors are creating or editing different reports in the same dataset, only the first person who opened a report can access the Calculations menu. The other editor will see the message “This resource is locked because it is currently being edited by <name>”. Once the first person closes the report, the Calculations menu will become available to the next editor. - Click Standard calculated attribute. A new blank attribute opens.
- Enter a name for the attribute like Tickets received by email.
- In the formula window, start entering your formula. There are a number of ways you can do this, but for now, under functions, click Add.
- Search for IF THEN ELSE Conditional expression. Either use the search box, click Filter to scope the values down to the Logical category, or scroll through the list until you find the function you want.
- Next to IF THEN ELSE Conditional expression, click +.
Explore adds a template IF THEN ELSE formula to the window. The values in the formula shown in blue (beginning with an _ character) are placeholders that you must replace with the values you need.
Tip: Notice the error message prefixed with () above the formula. This indicates a problem and its location in the formula. For now, you can ignore the error. It's appearing because your formula is still using placeholders.
- Next, you'll replace _boolean_condition with the Explore attribute you want to test. Either highlight _boolean_condition and then choose Ticket channel from the Fields menu, or amend the formula manually to add the attribute.
- Now, add the rest of the condition. To search for the string "Email", we add that to the
existing condition.
Your formula should now read IF ([Ticket channel]="Email") THEN _value_if_true ELSE _value_if_false ENDIF
- Next, add what you want to do if the condition is true, in this case return the ID of the ticket. Replace _value_if_true with [Ticket ID]. Notice that as you type [Ticket ID] that Explore automatically suggests matches to what you are typing. If the metric or attribute you want is shown, hit return to immediately complete entry of it.
- The ELSE clause shown in the template ticket can be used to provide an alternative action that will apply if the first condition is not true. In this case, we don't need it, so remove ELSE _value_if_false.
- You've now completed the formula. If all is well, you'll see something like the screen
below. Additionally. note that the error has gone and is replaced with a green check mark
to indicate that the formula is valid.
- Finally, click Save. The attribute you created can now be accessed by any of your Explore reports that use the same dataset. You can find it by clicking Add in any attribute panel and expanding Calculated attributes.
Adding metrics and attributes to your formula
It's likely that most of the formulas you write with Explore will use metrics or attributes from the dataset you are currently using. In the example above you used the attribute Ticket channel, but there are many hundreds more you can choose from.
While it can feel intimidating at first, most of these metrics and attributes have descriptive names that will help you to find what you need. Also, experiment with creating basic reports in Explore to learn more about what the various metrics and attributes do.
You can find a full list of all the metrics and attributes you can use in the Understanding Explore datasets.
To add a metric or attribute to your formula
- In the Explore formula window, click Select a field.
- Either scroll through the list, or type the first few letters of the metric or attribute
you want, to filter the list.
- Click the metric or attribute you want and it is added to the formula. In this case,
Ticket ID was chosen. Note how it is surrounded with brackets [].
The brackets indicate to Explore that this is a metric or attribute. An alternative method to enter a metric or attribute is to simply begin typing. Explore recognizes the brackets, and suggests the appropriate values to choose from.
If you want to add an aggregator to your metric or attribute, enter the text in capitals before the first bracket, for example COUNT[Ticket ID].
Adding functions to your formula
To add functions to your formula, click Add under Functions or type in a function name. As with metrics and attributes, Explore suggests auto-complete results for any functions you type in.
When you click Add, the Functions window opens. This window is useful if you are not sure which function is applicable to the calculated element you want to create. All functions in the window contain a brief explanation of their purpose. For a list of all functions and many examples, see Explore functions reference.
If you are looking for a specific function, you can search for functions or filter by function type.
- In the Functions window, click Filter.
- Type in a category or select a category from the drop-down list.
- Click the x next to the category name to remove the filter.
Adding comments to your formula
You can add comments to your formulas to explain how it works. This is helpful if you want to collaborate on formulas with other users, or if you want to make notes for yourself on why you built the formula the way you did.
To add a comment in a formula
- Find the place in a formula where you want to insert a comment.
- Type a forward slash and an asterisk (/*), type your comment, and then type an asterisk
and a forward slash (*/).Warning: Clicking Format removes all comments. If you click Format and want to restore your comments, click anywhere outside the panel to close it without saving your changes.
47 comments
Chris Wilbur
Hello!
Is there a way to add a wildcard into a formula? As a hypothetical, say I have a custom field that lists the country name and I want a report that filters just countries starting with "united" (United States, United Kingdom, etc). Is there a symbol I can use, such as below:
IF ([Country]="united%") THEN [ticket_ID] ENDIF
0
ZZ Graeme Carmichael
Cwilbur
You can use the STARTSWITH(_text,_text_to_search) function to do that.
IF STARTSWITH([Country],"united"]) THEN [ticket_ID] ENDIF
There are a few other similar text functions such as:
The full list of text functions is here.
0
Katie True
Hi, I'm trying to replicate the following Insights custom metric in Explore and can't seem to get the formula correct. Any advice?
0
Ahmed Mamdouh
1
Erin Miller
I'm trying to create a query that is basically - MUST HAVE Tag 1, and then display all other tags.
So end result is showing me how many tickets have tag 2, have tag 3, have tag 4, etc. but filtered on only those that ALSO have tag 1.
0
Rob Stack
Hi Erin Miller. I believe this custom metric will help. It's from the article Reporting with tags.
0
Erin Miller
Thank you! I am confused though, because I don't want to have to list out all the possible tickets there can be (tag 2, tag 3, tag 4) as those are ever changing. So its really "everything with tag 1" but then what I'm trying to do is count the number of tickets of each other type that has ticket 1. Does that make sense?
0
Rob Stack
Hi Erin Miller, here's another way around to try this. It should be a good starting point to get to what you need.
Create two standard calculated attributes.
The first has the formula:
IF INCLUDES_ALL([Ticket tags], "Tag 1") THEN [Ticket ID] ENDIF
And the second has the formula:
IF INCLUDES_ANY([Ticket tags], "Tag 2", "Tag 3","Tag 4") THEN [Ticket ID] ENDIF
(you might want to create three copies of that one so you can report on each tag separately).
Now, add the Tickets metric to the metrics panel and the two (or more) attributes you created to the Rows panel. You'll end up with something that looks like this:
You can then add further attributes to give you more information. I hope this works as a starting point for what you need!
1
Erin Miller
No, this still has the same problem. There is not a finite list of Tag 2, Tag 3, Tag 4... that I want to detail out in this procedure, as I do not want to rebuild this report every time more tags are are created it would be unscaleable the way we use zendesk.
What I'm really looking for is:
Show me all tickets with tag 1. Then DISPLAY FOR ME the number of tickets that have each and every other tag we have available. so end result will be:
100 tickets total with Tag 1. of those 100 tickets:
30 tickets have tag 4
15 tickets have tag 19
17 have tag 21
etc
0
Emily Czechowski
Hi all, I am wondering if it is possible to create a metric, attribute or query to identify tickets that contain certain words or strings of words? i.e. Get ticket numbers for all tickets that contain the words "alpha" and "beta". Must contain both to return ticket ID. How would I do this?
0
ZZ Graeme Carmichael
Emily
The ticket subject line can be checked for text, but ticket comments are not available in Explore.
To check the subject for both alpha and beta in any case, use a custom metric:
If you need to check if the phrases appear in the ticket comments you would need to set a triggers to check for each word. The trigger will set a tag if the word is present. You then create a metric to check for the tags.
0
Katie Barton
Hello,
Restating this question from 5 months ago. I'm trying to replicate the following Insights custom metric in Explore and can't seem to get the formula correct. Any advice?
0
Lauren Jeffreys
I am trying to create a standard calculated attribute that returns tickets that have two tags. I am using the recipe above for that, but it is still returning tickets that have one of those two tags.
I need the report to show only if the ticket is tagged with both cashorder AND contract_stage_1 but the recipe is allowing tickets that have one or the other, but not both.
IF (INCLUDES_ALL([Ticket tags], "cashorder","contract_stage_1")) THEN [Ticket ID] ENDIF
0
Marco
Cheers!
0
Delaney F.
Hi Zendesk Team -- I am using the SUM (% Achieved SLA) metric to track our achievement rate over the last 30 days.
I want to add a constant threshold, let's say at 90% for example, and have it added as a horizontal line on this graph. I would then like to calculate the amount of time we are above this threshold for the given time period (past 30 days in this example). I would like to be able to adjust the threshold, i.e. change it from 90% to maybe 95% in the future. Please advise. Thanks!
2
Dane
You can use trend lines to designate a constant value for your report. Refer to the screenshot.
When it comes to the formula that you have requested, there's no native function in Explore that can return the timestamp at which the metric exceeded (or fallen below) a trendline.
Hope this helps.
Cheers,
Dane
0
James Beniston
Hi Everyone,
I am trying to report on our onboarding efforts with customers, all the data on which is stored in Zendesk.
All of our onboarding process is handled via a single ticket per organization. I would like to count all of these tickets, i assume this could be done via creating a new standard calculated metric?
Something like: COUNT(Tickets)[Ticket form]="Customer Onboarding"
This one does not compute, i must be missing something...
What I would like to do then is slice the data on standard calculated attributes to say that:
I feel like i need the metric first an the rest will flow into place.
Any input on this would be awesome!
Cheers
James
1
Gab Guinto
Do these tickets have Customer Onboarding selected as their ticket form? If so, then you can try this custom metric formula:
This should give you the count of tickets with that selected form. You can compare it to or make further calculations along with the total count of tickets or your other custom metrics.
1
James Beniston
Thanks @..., i have what i need!
0
Raghul P
IF ([Ticket status]= "Open"AND NOT INCLUDES_ANY([Ticket tags], "tag1","tag2")
AND INCLUDES_ANY([Ticket tags], "tag1"))
THEN [Ticket ID] ENDIF
Under Standard Calculated Metric, the above formula shows as correct, but it is not producing any result, is this a correct form?
0
Alex Zheng
I will open up a ticket with you to take a look at your formula.
Best regards,
-1
Laura
Hey everyone,
I am confused about when to use parentheses ( ) and when to use brackets [ ]. I'll explain the context first before getting to the example wherein my confusion lies.
In the paragraph on 'Understanding Explore formulas', it is explained very clearly:
As I am currently working with the Guide - Knowledge Capture dataset, I am choosing an example here, but I have observed this in other datasets as well.
Here we have a metric called '% Ticket resolution rate'. It uses the formula:
D_COUNT(Resolution article tickets)/D_COUNT(Linked article tickets)
Both Resolution article tickets and Linked article tickets are metrics. They are calculated metrics that belong to the same dataset.
Why do these metrics not have to be inserted in brackets [ ] but are only in parentheses ( )?
Does this have something to do with whether or not the metric is a 'database counted metric'?
Any help will be appreciated! Thank you in advance!
0
Dane
The "[]" denotes that these are the base metrics and attribute values. "Resolution article tickets" is already a combination of multiple attributes in a function. Therefore it will be shown with "()".
Please refer to Guide Dataset for the formula.
0
Judy Correia
For newbies, a step is missing. You need to be in an existing report or creating a new report to access the calculations. This menu isn't just available from Explore landing page.
0
Dave Dyson
-1
Erin O'Callaghan
Thanks for pointing this out, Judy Correia! I've updated the first set of steps in this article to mention that you first need to create or open a report.
0
CJ Johnson
When a custom formula is updated, what is the expected behavior for every existing report with that formula in use?
0
Jon Daniels
Hey CJ Johnson!
When you use a formula to build a custom attribute or metric, it is expected that the attribute or metric works the same everywhere you use it, and will change in each report when the formula is changed.
If you don't see this happening, please message us - we'll be happy to assist!
0
CJ Johnson
Hi Jon,
Can you clarify if that means that a filter that is changed, should stay checked with the existing options, if that filter's formula is changed?
Can you clarify if Dashboards with reports on them, that contain formulas with updates, still need to be opened, have each tab with an affected report loaded, and have "publish" pushed for each one?
0
Jon Daniels
[Updated my own comment in 2023 with a correction: my original comment is not how it works, every change that changes a report (formula etc) requires that report to be re-published on the dashboard (as outlined here: https://support.zendesk.com/hc/en-us/articles/4408823403546-Editing-reports#:~:text=After%20you%20create%20a%20report,a%20report%20at%20a%20time.)
The changes to any formula should be effectively shown in the values on each of the reports/dashboards using the metric or attribute that the formula is based on - the filters would only be affected if they were based on the formula (for example, a date filter wouldn't be affected at all)
(Quickly editing to make it clear that the reports and dashboards should show the new values as soon as the formula they are based on changes, since the formula is what determines the value.)
If you're seeing something different happen in your experience, we can better help you with your specific issue once you message us directly.
0