Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Highlighted
swarnendu
Contributor II

auto generate value using script

Hi all,

I am facing a problem in script level.

Which is i need to create auto generate value using script.

my example is

Item NoItem idDateValuevalue2
201310101/01/20170100
201310102/01/20170100
201310103/01/2017100100
201310104/01/20170100
201310105/01/20179090
201310106/01/2017090
201310201/01/20170200
201310202/01/2017200200
201310203/01/20170200
201310204/01/2017170170
201310205/01/20170170

please see my table i have 3 dimension which is item no , item id and date,

and also a measure which name is value i need like value2 measure  using script.

If you have any solution then please suggest me.

Thanks and regards

Swarnendu

11 Replies
YoussefBelloum
Esteemed Contributor

Re: auto generate value using script

Hi,

what is the rules to calculate the Value 2 ?

swarnendu
Contributor II

Re: auto generate value using script

i used like this but its not working properly.

If(Item_no<>peek(Item_no) and Item_Id<>peek(Item_Id) and Date<>peek(Date),Value,Peek(Value)) as Value,

I need to generate the value filed  like value 2 field.

YoussefBelloum
Esteemed Contributor

Re: auto generate value using script

your script is working fine here, the Peek works fine, it will always gives you the ELSE part which is the Peek(Value) because the condition is never met, Item No is always the same on the table you gave

swarnendu
Contributor II

Re: auto generate value using script

I know this problem but have you any idea how i can do it?

if you have any idea then please share.

Regards

swarnendu

YoussefBelloum
Esteemed Contributor

Re: auto generate value using script

your calculation rules for Value2 field is simply wrong..

Try to define correct rules that can be applied to your data

swarnendu
Contributor II

Re: auto generate value using script

any suggestion ?

YoussefBelloum
Esteemed Contributor

Re: auto generate value using script

I really can't tell you how to calculate your field..

but the only peek that make sense here is the Peek(Date), because there are some Dates presents on differents lines for different Item_id's.

But the question is how did you calculate the values present on the VALUE2 column ??

qliksus
Valued Contributor II

Re: auto generate value using script

Maybe something like the below

A1:
load

ItemNo,
Itemid, Date, Value , if(Peek(Itemid)=Itemid and Value=0, Peek(Value),Value) as Values

Resident A
order by ItemNo,Itemid,Date
;

A2:
load

ItemNo,
Itemid, Date, Value , if(Peek(Itemid)=Itemid and Values=0, Peek(Valuesfinal),Values) as Valuesfinal

Resident A1
order by ItemNo,Itemid,Date desc
;


DROP Table A,A1 ;

swarnendu
Contributor II

Re: auto generate value using script

Can you please share your .qvw file