Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
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;
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>;
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;