Using the IF THEN ELSE function

Return to top


  • SEA|KL|Isaac Yew|AH|EN-SEA


    I'm trying to get the SLA of a certain region with certain group, but I want to exclude those ticket that has a custom tag. But it doesn't work, can any1 share some insight?

    IF ([Ticket group] = "XXX") 
    AND ([Region] = "XXX")
    AND (NOT INCLUDES_ANY([Ticket tags], "ticket_breached")
    THEN [SLA policy ticket ID]


  • Andrei Kamarouski

    Graeme, Eugene,

    Hi guys, 

    It seems that using attributes values directly in formulas is not working for proper calculations (I just receive all tickets instead of intended tickets with the non-blank value in my custom field).

    You are writing about using attributes in the formula, but showing examples with tags of those attributes. Is this the proper way to build metrics for custom ticket fields? The documentation is not clear here or do I miss something? 

  • Rob Stack
    Zendesk Documentation Team

    Hi Andrei Kamarouski, could you try removing the quotes from "NULL"? NULL isn't a value, it's essentially "nothing" :-) 
    There's a similar example of what you're trying to do in this article.

    I hope this helps, but do let us know if you need more help. Thanks!

  • Andrei Kamarouski

    Hi @..., I see now! =) Thx! 😊 

  • Adam Wideman

    I'm not sure if I'm doing this totally correct or if I need to make a whole different set of custom metrics to pull this off, but I'm trying to add some custom fields to my Organizations for "Service Agreements".  Each agreement, of which there are 3 for each organization possible, would have a "Contract Number", "Hours Purchased", and a "Contract Value".  I need to pull in Hours Purchased and Contract Number in order to run a query against how many "hours billed" against the "Hours Purchased".  I've been able to do this easily with just one contract, but now its causing some erroneous data when we have multiple contracts involved.  SO  I want a field thats SUPER smart.  I need one that knows to show hours purchased relevant to which Contract Number is used.  The matching field is called "Ticket Sage Reference" (also custom) and lives in the ticket.  I want to say something like

    IF ([Ticket Sage Reference]=VALUE(ContractNumber))
    THEN 1
    ELSE IF ([Ticket Sage Reference]=VALUE(ContractNumber2))
    THEN 2
    ELSE IF ([Ticket Sage Reference]=VALUE(ContractNumber3))
    THEN 3

    Then one that would ACTUALLY display the content

    IF ([CustomMetric]=1)
    THEN VALUE(ContractNumber1)
    ELSE IF ([CustomMetric]=2)
    THEN VALUE(ContractNumber2)
    ELSE IF ([CustomMetric]=3)
    THEN VALUE(ContractNumber3)

    I'm terrible with functions, please send help . I think I may even be at the point where I may even pay Zendesk to write this for me, but wanted to see if anyone could steer me in the right direction before i did that.

  • Rob Stack
    Zendesk Documentation Team

    Hi Adam Wideman, thanks for the question. I'm not sure if you can do exactly what you need here. However, I really think it would be worth you asking this in our Explore Q and A section at

    A lot more customers will see it there and it's always possible that someone has worked out a solution to this. Thanks!

  • CaSonya Featherston

    I have a question, I am trying to build a query for unsolved tickets with ID as well as the number of days the ticket has been open.  Would this be a IF-THEN-ELSE calculation or is there an attribute that will give me these results?

  • Elaine
    Zendesk Customer Care

    Hi CaSonya,

    Please check out the Explore recipe: Reporting on the duration of fields as that would provide you the time a ticket has been set to a specific status throughout its lifecycle. Hope this helps! :)


Please sign in to leave a comment.

Powered by Zendesk