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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
swati_rastogi27
Creator
Creator

Need help with fetching previous data

I have sample data as :

DATE_COL     EMP_ID     EMP_GRP_CODE     SOME_VALUE

01-JAN-16       11211          ABC                         23

01-JAN-16       11211         CDE                         34

01-JAN-16       11211          DEF                         45

02-JAN-16       11211          ABC                        

02-JAN-16       11211          CDE                        

02-JAN-16       11211          DEF                        

03-JAN-16       11211          ABC                        

03-JAN-16       11211          CDE                        

03-JAN-16       11211          DEF                        

04-JAN-16       11211          ABC                         67

04-JAN-16       11211          CDE                         89

04-JAN-16       11211          DEF                         90

05-JAN-16       11211          ABC                         11

05-JAN-16       11211          CDE                         12

05-JAN-16       11211          DEF                         13


My requirement is to roll/populate missing values for a combination of DATE_COL,EMP_ID and EMP_GRP_CODE.

Peek is not helping me, coz for row number 4, Peek will give me value from previous row, whereas , want value from row 1


Can someone help?

Labels (1)
1 Solution

Accepted Solutions
antoniotiman
Master III
Master III

See attachment.

Regards,

Antonio

View solution in original post

7 Replies
Anonymous
Not applicable

so what value do you want for row 4? Is it 23 as in row 1?

swati_rastogi27
Creator
Creator
Author

Yes exactly . It should be 23

antoniotiman
Master III
Master III

Is this what You want ?

swati_rastogi27
Creator
Creator
Author

Yes, this is exactly the output that I want.

Also , a simple group by on EMP_GRP_CODE will not work, because we have many EMP_IDs we well.

A peek without considering EMP_ID will result in fetching value from some other EMP_ID

Could you help me achieve this?

antoniotiman
Master III
Master III

See attachment.

Regards,

Antonio

Frank_Hartmann
Master II
Master II

try this in script:

Test:

LOAD * INLINE [

DATE_COL,        EMP_ID,        EMP_GRP_CODE,    SOME_VALUE

01-JAN-16,       11211,         ABC,            23

01-JAN-16,       11211,         CDE,            34

01-JAN-16,      11211,          DEF,             45

02-JAN-16,      11211,          ABC,           

02-JAN-16,      11211,          CDE,             

02-JAN-16,      11211,          DEF,                     

03-JAN-16,      11211,          ABC,                     

03-JAN-16,      11211,          CDE,                     

03-JAN-16,      11211,          DEF,                     

04-JAN-16,      11211,          ABC,          67

04-JAN-16,      11211,          CDE,          89

04-JAN-16,      11211,          DEF,           90

05-JAN-16,      11211,          ABC,          11

05-JAN-16,      11211,          CDE,          12

05-JAN-16,      11211,          DEF,           13

];

1:

Load

DATE_COL,      

EMP_ID,      

EMP_GRP_CODE,

if(SOME_VALUE='',peek('SOME_VALUE1',-1),SOME_VALUE) as SOME_VALUE1

Resident Test order by EMP_GRP_CODE,DATE_COL;

DROP Table Test;

hope this helps

sunny_talwar
MVP
MVP

Frank I would change this to something like this:

LOAD DATE_COL,     

          EMP_ID,     

          EMP_GRP_CODE,

          If(EMP_ID = Previous(EMP_ID) and EMP_GRP_CODE = Previous(EMP_GRP_CODE) and SOME_VALUE='', Peek('SOME_VALUE1'), SOME_VALUE) as SOME_VALUE1

Resident Test

Order By EMP_ID, EMP_GRP_CODE, DATE_COL;

Because just checking if SOME_VALUE is null may not be enough because if for some reason the previous EMP_GRP_CODE is not the same, it might pull the value from another EMP_GRP_CODE. I guess it works in this scenario, but I think putting it there in code is a practice I always follow.

Best,

Sunny