Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

galax_allu
Valued Contributor

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

Re: Country Wise sales thru Previous()

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;

3 Replies

Re: Country Wise sales thru Previous()

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
Valued Contributor

Re: Country Wise sales thru Previous()

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

galax_allu
Valued Contributor

Re: Country Wise sales thru Previous()

thanks ....a lot