Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
abhijith28
Creator II
Creator II

If the value is null or 0, then Previous value based on condition in Qliksense

Hi QlikExperts/ @sunny_talwar  @Kushal_Chawda 

I need your help to achieve the below scenario. Tried different use case but not able to produce the expected output.

Data Format (Input)

abhijith28_0-1606805696000.png

Expected Output

abhijith28_1-1606805842153.png

 

There are more than 40000 unique ID's. But all 40000 ID's data are not shown, always single "ID" will be selected by default.

In the above Expected output For ID=1, value = '-' (null)  is replaced by 20 but not for Date=1/1/2020 as 1/1/2020 is the starting point and there are no values(>0) Prior to the date 1/1/2020.

For ID=2, (3/2/2020 and 4/2/2020) is replaced by 40.

If the input data for ID=3 in the below format, then the output would be same as input as there are no Value prior to null values.

abhijith28_0-1606807260439.png

 

Please help me on this scenario.

Thanks,

 

 

 
 
 

 

 

 

Labels (1)
1 Solution

Accepted Solutions
Kushal_Chawda

12 Replies
PrashantSangle

do you want previous value or next value???

if want previous value then try below 

Table1:

Load ID,Date,if(IsNull(Value) or Value='-',peek(Value),Value) as Value inline [
ID,Date,Value
1, 1/1/2020, -
1, 2/1/2020, 10
1, 3/1/2020, -
1, 4/1/2020, 20
1, 5/1/2020, 30
2, 2/2/2020, 15
2, 3/2/2020, -
2, 4/2/2020, -
2, 5/2/2020, 40
2, 6/2/2020, 30
3, 1/1/2020, -
3, 2/1/2020, -
3, 3/1/2020, -
3, 4/1/2020, 20
3, 5/1/2020, 30
];

 

Thanks & Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
abhijith28
Creator II
Creator II
Author

@PrashantSangle 

I need next value, but it should follow certain rules.

1. ID=2 values should not replace ID=1 values. Replacing values should be within same ID.

2. For ID=3, there should not be any replacement of values, as there are no null values after the values>0. 

3, 1/1/2020, -
3, 2/1/2020, -
3, 3/1/2020, -
3, 4/1/2020, 20
3, 5/1/2020, 30

PrashantSangle

can you give sample input with required output...

 

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
abhijith28
Creator II
Creator II
Author

@PrashantSangle 

Please find the below input

abhijith28_0-1606817725375.png

 

Expected Output

 

abhijith28_1-1606817762988.png

 

Kushal_Chawda

@abhijith28  try below

Data:
LOAD ID,
     Date,
     Value
FROM table;

Final:
LOAD *,
     if(ID=previous(ID) and len(trim(Value))=0,peek(New_Value),Value) as New_Value
resident Data
order by ID, Date;

Drop table Data;
abhijith28
Creator II
Creator II
Author

@Kushal_Chawda 

Tried the same logic but unfortunately its not returning the expected output.

abhijith28_0-1606823739494.png

 

Please find the attached the sample app.

 

Thanks,

 

 

PrashantSangle

try this 

 

Table1:

Load ID,Date(Date#(Date,'DD/MM/YYYY'),'DD/MM/YYYY') as Date,Value inline [

ID,Date,Value
1, 1/1/2020, -
1, 2/1/2020, 10
1, 3/1/2020, -
1, 4/1/2020, 20
1, 5/1/2020, 30
1, 6/1/2020, -
2, 2/2/2020, 15
2, 3/2/2020, -
2, 4/2/2020, -
2, 5/2/2020, 40
2, 6/2/2020, 30
3, 1/1/2020, -
3, 2/1/2020, -
3, 3/1/2020, -
3, 4/1/2020, 20
3, 5/1/2020, 30
];

NoConcatenate
Table:
Load ID,Date,If(ID=3,Value,if(IsNull(Value) or Value = '-', peek(Value),Value)) as Value;
Load *
Resident Table1
order by Date desc;

Drop table Table1;

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
abhijith28
Creator II
Creator II
Author

@PrashantSangle 

There are more than 40k ID and it cannot be hardcoded ID=3

PrashantSangle

but somewhere you have to maintain that for which id you want to apply which rule for some which you don't want to apply rule.

you use match() or if you have less no id for which you have to apply rule then do little modification in that if statement and resolve your query

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂