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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
___dl
Contributor II
Contributor II

How to get the previous and next non-null value in the record?

I have thousands of rows of records and there are a lot of null values. I need to fill in these rows with the average of previous non-null value and next non-null value in my record. How do i do this? 

I would appreciate a quick response!

Labels (1)
1 Solution

Accepted Solutions
___dl
Contributor II
Contributor II
Author

Here is the solution I did to get the previous and next non-null values:

For Previous:

TABLE_1:

AUTONUMBER() AS Record_Number,

My_Field_Name,

IF( ISNULL(My_Field_Name), PEEK(My_Field_Name), My_Field_Name) AS My_Field_Name_Previous

 

For Next:

I loaded similar table but with ORDER BY Record_Number is DESC.

TABLE_2:

Record_Number,

My_Field_Name,

My_Field_Name_Previous,

IF( ISNULL(My_Field_Name), PEEK(My_Field_Name), My_Field_Name) AS My_Field_Name_NEXT

RESIDENT TABLE_1 ORDER BY Record_Number DESC;

DROP TABLE TABLE_1;

View solution in original post

2 Replies
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

In load script:

Data:

load *,

if(rowno()=1, <YourColumnName>,if(isnull(<YourColumnName>),peek([Non-null Value]),<YourColumnName>)) as

 [Non-null Value]

resident <YourTableName>;

drop table  <YourTableName>;

___dl
Contributor II
Contributor II
Author

Here is the solution I did to get the previous and next non-null values:

For Previous:

TABLE_1:

AUTONUMBER() AS Record_Number,

My_Field_Name,

IF( ISNULL(My_Field_Name), PEEK(My_Field_Name), My_Field_Name) AS My_Field_Name_Previous

 

For Next:

I loaded similar table but with ORDER BY Record_Number is DESC.

TABLE_2:

Record_Number,

My_Field_Name,

My_Field_Name_Previous,

IF( ISNULL(My_Field_Name), PEEK(My_Field_Name), My_Field_Name) AS My_Field_Name_NEXT

RESIDENT TABLE_1 ORDER BY Record_Number DESC;

DROP TABLE TABLE_1;