Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
rociotrevial
Creator
Creator

Calculated expresion (Expresion Calculada)

Good afternoon,

I have a pivot table with 2 expressions (Expenditure and% spent), something like this:

qv.GIF

And I want the expression called "Difference" The difference between the metric spending 2015 vs metric Expense 2014, ie, the difference in spending between each year is calculated, obvious is calculated field Difference in 2014 should zero as it has a prior year against which to compare, but in the case of 2015 should subtract for example for the region Op Mining 7253 -. 5941.

Then I put in the expression Difference:

= Column (4)-column (1)

but does not throw me any value, how I can do?

We appreciate your help

Translated with Google Translate - Qlik Community Administrative Team

Buenas tardes

Tengo una table pivote con 2 expresiones (Gasto y %Gastado), algo asi:

Y quiero que en la expression llamada "Diferencia" se calcule la diferencia que hay entre la metrica Gasto 2015 vs la métrica Gasto 2014, es decir, que se calcule la diferencia del gasto entre cada año, obvio el campo de Diferencia en el 2014 debe ser cero pues no tiene un año previo contra el cual comparar, pero para el caso del año 2015 debe restar por ejemplo para la region Op. Mineras 7253 - 5941.

Entonces  puse en la expression Diferencia:

=Column(4)-Column(1)

pero no me arroja ningún valor, como le puedo hacer?

Les agradezco su ayuda

3 Replies
Not applicable

Hi Rocio

From what you describe I think this is the result you wish to achieve:

To begin I copied the data from your table to create a fact table:

   

Region
GastoYear
OP.Mineras59412014
OP.Mineras72632015
Staff255242014
Staff541712015
Puebla-Ver54302014
Puebla-Ver60332015
Golfo46302014
Golfo64232015
Centro40832014
Centro38012015
Agricola11832014
Agricola16012015
Tamps. Sur42862014
Tamps. Sur43162015

I then created a pivot table using Region and Year as the dimensions with the following expressions:

Gasto: Sum (Gasto)

% of Total: Num(Sum(Gasto) /Sum(TOTAL <[Year]> Gasto) ,'0.00%')

Difference from previous year: Sum(Gasto-aggr(above(sum({<Year=>} Gasto)), RegionYear))

The order of the fields in the aggregation statement is critical in this expression.

The resulting calculated fields give you the difference between the value against the region in the current year compared to the value in the region in the previous year.

I hope that helps.

Kind regards

Steve

PS I will put this through Google translate to attempt to turn it into Spanish for you.

/********************************************************************************************************************************/

Hola Rocio

De lo que usted describe Creo que este es el resultado que se desea lograr :

Para empezar he copiado los datos de su tabla para crear una tabla de hechos :

Region
GastoYear
OP.Mineras59412014
OP.Mineras72632015
Staff255242014
Staff541712015
Puebla-Ver54302014
Puebla-Ver60332015
Golfo46302014
Golfo64232015
Centro40832014
Centro38012015
Agricola11832014
Agricola16012015
Tamps. Sur42862014
Tamps. Sur43162015
Entonces creé una tabla dinámica utilizando Región y Año como las dimensiones con las siguientes expresiones :

Gasto: Sum (Gasto)

% Del Total: Num(Sum(Gasto) /Sum(TOTAL <[Year]> Gasto) ,'0.00%')

Diferencia con el año anterior: Sum(Gasto-aggr(above(sum({<Year=>} Gasto)), RegionYear))

El orden de los campos en el estado de agregación es crítico en esta expresión. Los campos calculados resultantes le dan la diferencia entre el valor en contra de la región en el año actual en comparación con el valor en la región en el año anterior.

Espero que eso ayude.

saludos cordiales

Steve

PS pondré esto a través de Google Translate para intentar convertirlo en español para ti.

rociotrevial
Creator
Creator
Author

Muchas gracias,

Lo hice de la forma en que me indicas, pero no se porque no me esta funcionando, me arroja el valor del gasto del año anterior en lugar de la diferencia que hay entre el gasto de un año y otro.

No se que podra ser, ya que esta exactamente como me indicas:

=Sum(Gastos_MXN-Aggr(above(sum({<Año=>} Gastos_MXN)), RegionAño)) 

tabla.GIF

Not applicable

Hi Rocio

Not sure why that is not working for you.  I'll provide some screen shots below to help you to compare your application with my working version.  I have added some more data to cover more years, have removed the % of total column and have added drop down selectors to the dimensions so the pivot chart is consistent in structure to your image.

First question is whether your data model is the same as the one I have used.  If not you may need to translate your data to match the structure shown below.

My sample data was from an Excel spreadsheet and was formatted as:

   

RegionGastoYear
OP.Mineras60452011
OP.Mineras56002012
OP.Mineras58002013
OP.Mineras59412014
OP.Mineras72632015
Staff194562011
Staff185262012
Staff223652013
Staff255242014
Staff541712015
Puebla-Ver38652011
Puebla-Ver50122012
Puebla-Ver48562013
Puebla-Ver54302014
Puebla-Ver60332015
Golfo40032011
Golfo42562012
Golfo45002013
Golfo46302014
Golfo64232015
Centro28942011
Centro39562012
Centro38252013
Centro40832014
Centro38012015
Agricola10562011
Agricola11882012
Agricola12032013
Agricola11832014
Agricola16012015
Tamps. Sur41092011
Tamps. Sur43252012
Tamps. Sur42542013
Tamps. Sur42862014
Tamps. Sur43162015

Second thing to check is the dimensions and expressions:

Expressions:

Sum (Gasto)

Sum(Gasto-aggr(above(sum({<Year=>} Gasto)), RegionYear))

The result of this in my application is:

I repeated the application changing my column names to match yours and using your formula

=Sum(Gastos_MXN-Aggr(above(sum({<Año=>} Gastos_MXN)), RegionAño)) 

and it worked giving the same result as above so your formula is correct.

I tried a few manipulations to see if I could repeat your error but as yet I have not managed to repeat it.

Hopefully this will help you to spot the issue and resolve it.

Kind regards

Steve