# Calculo con varias condiciones

Buenas tardes, tengo la siguiente dura,

Requiero calcular un campo que tiene varias condiciones, pero cuando uso el ifelse me genera un error
ifelse({segmenttype}=‘interact’ AND {purpose}=‘customer’ AND {mediatype_cd}=‘voice’,{handle_}/{chandle_}), me dice que la sintaxis no es correcta
le agrego un cero al final
ifelse({segmenttype}=‘interact’ AND {purpose}=‘customer’ AND {mediatype_cd}=‘voice’, {handle_}/{chandle_}, 0)
pero me dice lo siguiente Falta una función de agrupación. Las agregaciones personalizadas no pueden contener simultáneamente campos de agregación y de no agregación en cualquier combinación.
Porque me genera ese error los campo usados son los siguientes
handle_=sum(handle)/1000
chandle=sum(chandle)

Me podrian ayudar gracias

1 Like

Hello @Santi98, what type of visual are you adding this calculated field in? I am wondering if you try writing it this way, if it would resolve the error and still give you the expected output:

``````ifelse(
{segmenttype}='interact' AND {purpose}='customer' AND {mediatype_cd}='voice',
({handle}/ 1000)/{chandle},
NULL
)
``````

You may not need to use the sum aggregation within the ifelse statement to return the proper values. Let me know if this helps!

Hi @DylanM si no hago la suma primero de esos campos y luego la división, el valor me da mas alto con la solución que me brindas

1 Like

Hello @Santi98, then maybe if we break it up into 3 calculated fields, we can bypass the aggregation error. 2 calculated fields can be made to return handle and chandle if they meet the requirements of the ifelse statement, then the third can run the calculation.

handle_ =

``````ifelse(
{segmenttype}='interact' AND {purpose}='customer' AND {mediatype_cd}='voice',
{handle},
NULL
)
``````

chandle_ =

``````ifelse(
{segmenttype}='interact' AND {purpose}='customer' AND {mediatype_cd}='voice',
{chandle},
NULL
)
``````

final = `(sum({handle_})/1000)/sum({chandle_})`

Let me know if this helps!

Hello @Santi98, since we have not heard back from you, I will mark my last response as the solution. Let me know if you have any follow-up questions on this issue, and I can assist you further. Thank you!

hola @DylanM, lo tuve que solucionar desde el motor de base de datos, porque no funciono desde QS