Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Shahzad_Ahsan
Creator III
Creator III

Get Previous Date Value if No Value in next date

Hi 

I have a table like this

T1:

CategoryDateValue
A03/12/2019968
B03/12/2019478
C03/12/2019259
D03/12/2019478
A04/12/2019300
B04/12/2019658
C04/12/2019478
D04/12/2019214
A05/12/2019200
D05/12/2019800

 

I need result like this

T2:

CategoryDateValue
A03/12/2019968
B03/12/2019478
C03/12/2019259
D03/12/2019478
A04/12/2019300
B04/12/2019658
C04/12/2019478
D04/12/2019214
A05/12/2019200
B05/12/2019658
C05/12/2019478
D05/12/2019800

 

The difference is, if you look at T1 there is missing value for Category B and C for 05/12/2019 

If want to insert Category B and C for 05/12/2019 with the same value of B and C from 04/12/2019

I need 4 rows for each date from first date till today. 

Please suggest how to achieve this from load script.

 

Labels (1)
1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

hi 

this script is an example , that gives you what you looked for 

T1temp:
LOAD * INLINE 
[
Category,Date,Value
A,03/12/2019,968
B,03/12/2019,478
C,03/12/2019,259
D,03/12/2019,478
A,04/12/2019,300
B,04/12/2019,658
C,04/12/2019,478
D,04/12/2019,214
A,05/12/2019,200
D,05/12/2019,800
](delimiter is ',');

///////////creating a table with all dates and all category //////////////////////
T2temp:
load Distinct Date
Resident T1temp;
Join
load Distinct Category
Resident T1temp;
/////////////adding the actual data to the full table //////////////////////////////
left join (T2temp)
load *
Resident T1temp;

drop Table T1temp;
////////////////filling the missing values //////////////////
T2:
load *,
if(len(Value)<1,if(Previous(Category)=Category, peek('fullValue'),0),Value) as fullValue
Resident T2temp
Order by Category,Date;

drop table T2temp;

View solution in original post

2 Replies
lironbaram
Partner - Master III
Partner - Master III

hi 

this script is an example , that gives you what you looked for 

T1temp:
LOAD * INLINE 
[
Category,Date,Value
A,03/12/2019,968
B,03/12/2019,478
C,03/12/2019,259
D,03/12/2019,478
A,04/12/2019,300
B,04/12/2019,658
C,04/12/2019,478
D,04/12/2019,214
A,05/12/2019,200
D,05/12/2019,800
](delimiter is ',');

///////////creating a table with all dates and all category //////////////////////
T2temp:
load Distinct Date
Resident T1temp;
Join
load Distinct Category
Resident T1temp;
/////////////adding the actual data to the full table //////////////////////////////
left join (T2temp)
load *
Resident T1temp;

drop Table T1temp;
////////////////filling the missing values //////////////////
T2:
load *,
if(len(Value)<1,if(Previous(Category)=Category, peek('fullValue'),0),Value) as fullValue
Resident T2temp
Order by Category,Date;

drop table T2temp;
Shahzad_Ahsan
Creator III
Creator III
Author

Thanks Buddy

This is what I needed