Calculate a new column with data from N-1 /Calculer une nouvelle colonne avec les données de N-1

Solved!
DaitakuNapoleon
Level 2
Calculate a new column with data from N-1 /Calculer une nouvelle colonne avec les données de N-1

Bonjour à tous,

je souhaite lancer ici un appel à l'aide car je suis bloqué sur une opération qui me paraît compliquée. Je précise que je suis encore débutant sur Dataiku.

Voilà mon problème je dispose des données de ventes de plusieurs magasins sur 2017, 2018 et 2019 et je voudrais ajouter une colonne de variation des ventes.

La colonne pour les ventes de 2017 serait vide et commencerait à se remplir à partir de Janvier 2018 dans laquelle la variation entre Janvier 2018 et Janvier 2017 sur le magasin x serait exprimée en %. [(Valeur des ventes du magasin x sur 2018 - Valeur des ventes du magasin x sur 2017) / Valeur des ventes du magasin x sur 2017].

L'inconvénient est que j'ignore comment faire cette opération dans un "prepare" sur Dataiku. J'ai réalisé une maquette de ce que je souhaiterais faire sur Excel (en jaune).

Merci de votre aide !

 

 

Good evening,

I would like to appeal for help here because I am stuck on an operation that seems complicated to me. I specify that I am still a beginner on Dataiku.

That's my problem I have sales data from several stores on 2017, 2018 and 2019 and I would like to add a column of sales variation.

The column for 2017 sales would be empty and start to fill from January 2018 in which the variation between January 2018 and January 2017 on store x would be expressed in%. [(Value of store sales x over 2018 - Value of store sales x over 2017) /  value of store sales x over 2017].

The downside is that I don't know how to do this in a "prepare" on Dataiku. I made a model of what I would like to do in Excel (in yellow).

Thanks for your help!

0 Kudos
1 Solution
StanG
Dataiker

Hi,

You can use a window recipe for your problem.

In the windows definitions step, choose Store and Month as Partitioning columns and Year as Order column (in ascending order).

In the aggregations step, choose Lag and Lagdiff and set 1 as offset to retrieve the sales value of the preceeding year.

This window recipe will output a dataset with two extra columns: the sales value of the preceeding year and the difference in sales.

You then have to do a prepare recipe to compute the variation rate using a formula step.

Best,

Stan

View solution in original post

1 Reply
StanG
Dataiker

Hi,

You can use a window recipe for your problem.

In the windows definitions step, choose Store and Month as Partitioning columns and Year as Order column (in ascending order).

In the aggregations step, choose Lag and Lagdiff and set 1 as offset to retrieve the sales value of the preceeding year.

This window recipe will output a dataset with two extra columns: the sales value of the preceeding year and the difference in sales.

You then have to do a prepare recipe to compute the variation rate using a formula step.

Best,

Stan