Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

New field in model

Hi,

I'm new to QlikView and I have small requirement which I'm unable to do it.

I want to create a new field in my model called as Previous Inventory.

Which should have the first row as zero and all the other rows should have the same records as the inventory field.

Inventory={23,25,29,37,70}

Previous Inventory={0,23,25,29,37,70}

6 Replies
maxgro
MVP
MVP

TMP:

LOAD *, alt(Peek('Inventory'), 0) as [Previous Inventory] INLINE [

    Inventory

    23

    25

    27

    29

    30

];



or if you want a field with all the values (NewField), add to previous code

load Concat([Previous Inventory], ',') as NewField

Resident TMP;

Not applicable
Author

Hello Max,

Thanks for the quick reply.

But the last record is being missed.

Temp1:

LOAD * INLINE [

    Inventory

    23

    25

    29

    37

    70

];

Temp2:

Load

Inventory,

alt(Peek('Inventory'),0) as [Previous Inventory]

resident Temp1;

Drop table Temp1;

inv.jpg

maxgro
MVP
MVP

maybe this?

1.png

TMP:

LOAD rowno() as id, *, alt(Peek('Inventory'), 0) as [Previous Inventory] INLINE [

    Inventory

    23

    25

    29

    37

    70

];

Concatenate (TMP)

first 1 load

'?' as Inventory, Inventory as [Previous Inventory]

Resident TMP

Order by id desc;

DROP Field id; 

Not applicable
Author

The image is what I want.

But the script returns '?' as the first record in Inventory.

Is there a way to push it at the end

1.jpg

maxgro
MVP
MVP

sort by load order in sort tab

1.png

Not applicable
Author

Hi Max,

The problem I'm facing here is, after creating the previous inventory field, I need to do the average of inventory and previous inventory.

A sort on the front end won't give me accurate values.

Hope I'm precise in explaining the requirement/issue.

Regards,

Adi