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: 
HemanthSai
Contributor
Contributor

[resolved]How to pass records to output based on a dynamic column value ?

Hi

I have a requirement to output records with a certain column value which is dynamic.

ColA ColB ColC ColE

1 A 09/15/2021 L

2 B 09/15/2021 M

3 C 09/15/2021 N

4 D 09/15/2021 O

5 E 09/14/2021 P

6 F 09/14/2021 Q

Data is similar to the above table.I want all the records with date 09/15/2021 to output and I do not need rest of the data. In essence I need all the records with the date value in the first record.

I have experimented using tmemorizerows and tjavarow but it did not worked,

Can any one help me with the issue ?

 

Edit:

Date field is not constant. It comes from a file and then I sort the data based on Date in descending order.

 

tfileInputDelimited-->tSortorder(based on date)-->somecomponent-->Outputfile(which should have all the records for the top date field )

Labels (3)
1 Solution

Accepted Solutions
gjeremy1617088143

your tjava row will be like this

if((Date)(globalMap.get("firstDate") ==null)

{

globalMap.put("firstDate",input_row.colB);

}

output_row.colA = input_row.colA;

output_row.colB = input_row.colB;

....

output_row.colD= input_row.colD;

 

so when the first row pass it will read "firstDate" see it's a null value and set it with the date of the first row

then each next row will don't pass in the if cause firstDate is no more null

 

tsetglobalvar-->on component ok-->inputfile-->tsortrow-->tjavarow-->tfilterrow-->tlogrow

View solution in original post

11 Replies
gjeremy1617088143

hi, if your field colB is a String you can use a tFilteRow component,

you Use advanced mode and in the texbox you can set :

"09/15/2021".equals(input_row.ColB)

 

Send me love and Kudos

HemanthSai
Contributor
Contributor
Author

Hi Jeremy,

It is not a string field. It is a date field and it is not constant.

gjeremy1617088143

TalendDate.compareDate(input_row.ColB,TalendDate.parseDate("MM/dd/YYYY", "09/15/2021"),"MM/dd/YYYY")==0

 

 

HemanthSai
Contributor
Contributor
Author

I cannot hardcode it, whatever the date that is in the first record, I need all the records for that date.

gjeremy1617088143

you can read the file (just the first line) (you can set header,footer and limit in tfileinputdelimited)

then you stock it in a globalmap (you can use tSetGlobalVar component then you call it in the t filterRow :

TalendDate.compareDate(input_row.ColB,your globalvar,"MM/dd/YYYY")==0

HemanthSai
Contributor
Contributor
Author

then I need to load my input file two times right. For storing first record date I will set the limit to 1 and store that in tsetglobalvar. for filtering the data I need to load the input file again,because we had set the limit to 1. I do not want to load the twice. Job should look something like this

Input file-->sort data on date-->logic/component to filter all line items for date in first record-->output file

gjeremy1617088143

you can create a new globalmap named firstDate with null value:

then you add this a the top a tjavarow code after push the synchronize button and generate code button:

 

if((Date)(globalMap.get("firstDate") ==null)

{

globalMap.put("firstDate",input_row.colB);

}

 

 

finally you can use tfilter row :

TalendDate.compareDate(input_row.ColB,(Date)(globalMap.get("firstDate"),"MM/dd/YYYY")==0

 

 

 

HemanthSai
Contributor
Contributor
Author

Here in this logic

if((Date)(globalMap.get("firstDate") ==null)

{

globalMap.put("firstDate",input_row.colB);

}

 

I am not able to store one value into the globalmap,it will store entire column.So I have tried something like this but it giving an error

 

if((Date)(globalMap.get("firstDate") ==null)

{

globalMap.put("firstDate",input_row.colB[1]);

}

My job is like this:

 

Inputfile-->tsortrow-->tsetglobalvar-->tjavarow-->tfilerrows-->tlogrow.

 

 

 

gjeremy1617088143

your tjava row will be like this

if((Date)(globalMap.get("firstDate") ==null)

{

globalMap.put("firstDate",input_row.colB);

}

output_row.colA = input_row.colA;

output_row.colB = input_row.colB;

....

output_row.colD= input_row.colD;

 

so when the first row pass it will read "firstDate" see it's a null value and set it with the date of the first row

then each next row will don't pass in the if cause firstDate is no more null

 

tsetglobalvar-->on component ok-->inputfile-->tsortrow-->tjavarow-->tfilterrow-->tlogrow