Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
mcaahmad93
Contributor
Contributor

Get the last year sales using script level.

Hi Team,

I have sample sales data based on that i need to get the last year sales.

attached the sample excel file

I am using the below script to get this done but not coming properly. Please suggest me.

Year_data:
LOAD Period,
Sales,
Year(Period) as Period_Year

FROM
[Last Year data.xlsx]
(ooxml, embedded labels, table is Sheet1);

Previous:
Load
Period,
Sales,
Period_Year,
if(Period_Year<>Previous(Period_Year),Sales,0) as Last_Year_Sales
Resident Year_data;
//If(Period_Year = Previous(Period_Year), Alt(Peek('Sales'), 0), 0) as Last_Year_Sales

DROP table Year_data;

Output should be like this:

PeriodSalesLast Year Sales
1-Jan-1810
1-Feb-1820
1-Mar-1830
1-Apr-1840
1-May-1850
1-Jun-1860
1-Jul-1870
1-Aug-1880
1-Sep-1890
1-Oct-18100
1-Nov-18110
1-Dec-18120
1-Jan-19131
1-Feb-19142
1-Mar-19153
1-Apr-19164
1-May-19175
1-Jun-19186
1-Jul-19197
1-Aug-19208
1-Sep-19219
1-Oct-192210
1-Nov-192311
1-Dec-192412

 

Regards,

Irshad Ansari

1 Solution

Accepted Solutions
asinha1991
Creator III
Creator III

now I understand what you want, do this

 

Previous:
Load
Period,
Sales,
Period_Year,
if(month(Period)=month(peek(Period)),peek(Sales),0) as Last_Year_Sales
Resident Year_data order by  month(Period),Period_Year;

View solution in original post

6 Replies
asinha1991
Creator III
Creator III

are you sure its ordered in original dataset? otherwise use peek with order by

 

Previous:
Load
Period,
Sales,
Period_Year,
if(Period_Year<>peek(Period_Year),Sales,0) as Last_Year_Sales
Resident Year_data order by  Period_Year;

mcaahmad93
Contributor
Contributor
Author

Thank you @asinha1991  for your valuable time.

i tried your script but value is not coming expected level.

Please find the attached data source based on that i need last year sales data.

Regards,

Irshad Ansari

asinha1991
Creator III
Creator III

now I understand what you want, do this

 

Previous:
Load
Period,
Sales,
Period_Year,
if(month(Period)=month(peek(Period)),peek(Sales),0) as Last_Year_Sales
Resident Year_data order by  month(Period),Period_Year;

StarinieriG
Partner - Specialist
Partner - Specialist

Hi,

you could try this instead

OUTPUT:
LOAD Period,
Sales,
Year(Period)-1 & Month(Period) as Last_Year
FROM
[Last Year data.xlsx]
(ooxml, embedded labels, table is Sheet1);

Left Join
LOAD
Year(Period) & Month(Period) as Last_Year,
Sales as Last_Year_Sales
Resident OUTPUT;

mcaahmad93
Contributor
Contributor
Author

Thank you @asinha1991  now its working perfectly.

 

mcaahmad93
Contributor
Contributor
Author

Thank you @StarinieriG  for you valuable time.

Regards,

Irshad Ansari