9 Replies Latest reply on Sep 12, 2017 3:42 PM by Okechukwu Ossai

# Aggregate value in if statement in LOD Expression

i'm trying to make a LOD expression like this

{ INCLUDE : IIF( [Des Origen Ingreso Producto] = "ADMINISTRATIVO" , [Calculo Medida] , NULL ) }

But [Calculo Medida] is an aggregate value. what can i do to fix that?

• ###### 1. Re: Aggregate value in if statement in LOD Expression

What is the error you getting. Can you attach workbook?

• ###### 2. Re: Aggregate value in if statement in LOD Expression

You can either aggregate the non-aggregate field or un-aggregate the aggregate field.

So, Try MIN([Des Origen Ingreso Producto]) = "ADMINISTRATIVO"

Or you can use FIXED to un-aggregate [Calculo Medida]. Consider attaching a sample workbook if you need further help.

Ossai

• ###### 3. Re: Aggregate value in if statement in LOD Expression

Is there specific reason why you're using INCLUDE?

Regardless, you can do the if statement at the individual base measure level.

So lets say Calculo Medida = SUM(A) - SUM(B)

You can do the if statement such that:

A_calc = IIF([Des Origen Ingreso Producto] = "ADMINISTRATIVO", [A], NULL)

B_calc = IIF([Des Origen Ingreso Producto] = "ADMINISTRATIVO", [B], NULL)

Now Calculo Medida becomes SUM(A_calc) - SUM(B_calc)

Is this what you were looking for?

• ###### 5. Re: Aggregate value in if statement in LOD Expression

No, this is not what i'm looking for

• ###### 7. Re: Aggregate value in if statement in LOD Expression

Try this.

{ INCLUDE : IIF( MIN([Des Origen Ingreso Producto]) = "ADMINISTRATIVO" , [Calculo Medida] , NULL ) }

Ossai

## Thank you Okechukwu Ossai

But, how is possible? [Des Origen Ingreso Producto] is a Dimension/ String,  and you put  MIN([Des Origen Ingreso Producto]

How Tableau understand that?

• ###### 9. Re: Aggregate value in if statement in LOD Expression

You're welcome Pahola. MIN() and MAX() can be used for strings, dates and numbers. When used for strings, Tableau will find the minimum alphabetically. For example, MIN(A, B) = A.

However, in you case it didn't matter since the operation is taking place at the row level. For example, MIN(A) = A.

Hope this helps.

Ossai