Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Country Wise sales thru Previous()

Hi,

I tried  for country wise sales , if two rows have similar country's data ;

But I am not sure why it is not working  'USA'  ? in 'TABLE BOX'

TEMP1:

LOAD * INLINE

[

COUNTRY, PRODUCT, SALES

MEXICO, A, 10000

ENGLAND, B, 100

USA, C, 4545

FRANCE, A, 7778

FRANCE,A, 8000

USA, B, 99999

INDIA, C, 12120

]

;

NoConcatenate

TEMP2:

LOAD COUNTRY, PRODUCT, SALES ,

if(COUNTRY=PREVIOUS(COUNTRY),PREVIOUS(SALES)+SALES, NULL()) AS COUNTRYWISESALES

Resident TEMP1;

DROP TABLE TEMP1;

TABLE BOX :

1 Solution

Accepted Solutions
sunny_talwar

Did you forget to may be add Order By Statement here?

TEMP1:

LOAD * INLINE

[

COUNTRY, PRODUCT, SALES

MEXICO, A, 10000

ENGLAND, B, 100

USA, C, 4545

FRANCE, A, 7778

FRANCE,A, 8000

USA, B, 99999

INDIA, C, 12120

]

;

NoConcatenate

TEMP2:

LOAD COUNTRY, PRODUCT, SALES ,

  if(COUNTRY=PREVIOUS(COUNTRY),PREVIOUS(SALES)+SALES, NULL()) AS COUNTRYWISESALES

Resident TEMP1

Order By COUNTRY; //or Order By COUNTRY, PRODUCT asc/desc;

DROP TABLE TEMP1;

View solution in original post

3 Replies
sunny_talwar

Did you forget to may be add Order By Statement here?

TEMP1:

LOAD * INLINE

[

COUNTRY, PRODUCT, SALES

MEXICO, A, 10000

ENGLAND, B, 100

USA, C, 4545

FRANCE, A, 7778

FRANCE,A, 8000

USA, B, 99999

INDIA, C, 12120

]

;

NoConcatenate

TEMP2:

LOAD COUNTRY, PRODUCT, SALES ,

  if(COUNTRY=PREVIOUS(COUNTRY),PREVIOUS(SALES)+SALES, NULL()) AS COUNTRYWISESALES

Resident TEMP1

Order By COUNTRY; //or Order By COUNTRY, PRODUCT asc/desc;

DROP TABLE TEMP1;

alexpanjhc
Specialist
Specialist

previous() will need to be used in a sorted file.

try this

TEMP1:

LOAD * INLINE

[

COUNTRY, PRODUCT, SALES

MEXICO, A, 10000

ENGLAND, B, 100

USA, C, 4545

FRANCE, A, 7778

FRANCE,A, 8000

USA, B, 99999

INDIA, C, 12120

]

;

NoConcatenate

TEMP2:

LOAD *

Resident TEMP1

order by COUNTRY, PRODUCT;

DROP TABLE TEMP1;

NoConcatenate

TEMP3:

LOAD COUNTRY, PRODUCT, SALES ,

if(COUNTRY=PREVIOUS(COUNTRY),PREVIOUS(SALES)+SALES, NULL()) AS COUNTRYWISESALES

Resident TEMP2;

DROP TABLE TEMP2;

Capture1.PNG

Anonymous
Not applicable
Author

thanks ....a lot