Ho to get a particular set of values from another set of values | Community
Skip to main content
Level 4
January 18, 2022
Solved

Ho to get a particular set of values from another set of values

  • January 18, 2022
  • 4 replies
  • 3210 views

Hi Team,

 

I want to filter out some records based on the below conditions.

example:

Input records:

customer idcustomer typeDate
1Full time01-01-2016
1Full time01-01-2018
1Full time03-01-2020
1Part Time04-01-2021
1Part Time01-01-2015
2Full time06-01-2016
2Part Time01-01-2019
3Full time08-01-2016
3Part Time12-01-2016
3Part Time10-01-2017
3Part Time18-01-2021
4Full time12-01-2016

 

Output records expected:

On first run:

customer idcustomer typeDate
1Full time01-01-2016
1Full time01-01-2018
1Full time03-01-2020

 

On second run:

customer idcustomer typeDate
1Part Time04-01-2021
1Part Time01-01-2015

 

On third run:

customer idcustomer typeDate
2Full time06-01-2016

 

Etc

 

So basically i want a filtering technique which will filter out all the records for that particular customer with same customer type.

I tried with deduplication but only the latest one or any random one is coming.

Could someone please help me in this?

 

@_manoj_kumar_  @jyoti_yadav 

 

Thanks &regards

Greeshma

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jyoti_Yadav

Hi @greeshma_sampath1 ,

 

You can use below logic.

 

1) Use query activity to fetch all the customers. Here your output will have all the records from customer table. Define one variable, : vars.customerId = "1";

2) Add test activity to check if number of records greater than zero.

3) Use 'split' activity. Split all your customers based on different types of customer type. Also customer Id equals to $(vars/@customerId);

Also, add the complimentary branch. This will have all the records other than customer Id 1.

4) Continue with complimentary branch. Use Javascript to increment the vars.customerId variable by 1.

5) Use wait activity. Give wait time of 5 sec. Connect the output branch to Step 2, 'test' activity.

 

Thanks,

Jyoti

4 replies

David_Loyd
Adobe Employee
Adobe Employee
January 18, 2022

Have you tried a split on customer type then a dedup on customer id? in the dedup you can use the advanced tab to keep the oldest or newest based on the date.

Level 4
January 18, 2022

Hi @david_loyd ,

 

Thanks for the response.

 

Split on a particular customer id will not help is what i thought as the customer ids can be hundreds or thousands so a generic way to filter is what iam looking for.

 

David_Loyd
Adobe Employee
Adobe Employee
January 18, 2022

Split on customer TYPE (not customer ID) is what I was recommending. Based on your data set seems you only want "Full Time"

Jyoti_Yadav
Jyoti_YadavAccepted solution
Level 8
January 19, 2022

Hi @greeshma_sampath1 ,

 

You can use below logic.

 

1) Use query activity to fetch all the customers. Here your output will have all the records from customer table. Define one variable, : vars.customerId = "1";

2) Add test activity to check if number of records greater than zero.

3) Use 'split' activity. Split all your customers based on different types of customer type. Also customer Id equals to $(vars/@customerId);

Also, add the complimentary branch. This will have all the records other than customer Id 1.

4) Continue with complimentary branch. Use Javascript to increment the vars.customerId variable by 1.

5) Use wait activity. Give wait time of 5 sec. Connect the output branch to Step 2, 'test' activity.

 

Thanks,

Jyoti

Krishnanunni
Level 4
January 19, 2022

Hi @greeshma_sampath1 ,

If I understand the requirement correctly, then what you would like to have is a looped execution of query with different results at each execution. I think the following structure of workflow might satisfy that requirement.

I have created a file based on your data and loaded using the data loading.
Code inside definition:

var query = xtk.queryDef.create(
  <queryDef schema={vars.targetSchema} operation="select">
    <select>
      <node expr="customer_id"/>
      <node expr="customer_type"/>
    </select>
  </queryDef>
)

var res = query.ExecuteQuery()

var keyValPair = {};
for each (var row in res)  {
  logInfo(row.customer_id);
  logInfo(row.customer_type);
  keyValPair[row.customer_id+row.customer_type] = [row.customer_id, row.customer_type];
}

keys=[];
vals=[];
len = 0;
for (var item in keyValPair) {
     keys.push(item);
     vals.push(keyValPair[item]);
     len++;
}
//logInfo(keys)
instance.vars.combinations = vals;



//loop variable
instance.vars.loop = 0;
instance.vars.loopLength= len;

You may skip data loading as you would have the original data in some schema. So replace the {var.targetSchema} with schema name like "nms:recipient". You might need to add '@' before column names when using schema. 

Code inside loop definition:

instance.vars.cust_id = instance.vars.combinations[instance.vars.loop][0];
instance.vars.cust_type = instance.vars.combinations[instance.vars.loop][1];

In query activity, set the value expression as in below ss

Code in JavaScript code 3

instance.vars.loop++;

Test activity



 

 

Sukrity_Wadhwa
Community Manager
Community Manager
January 27, 2022

Hi @greeshma_sampath1,

Were you able to resolve this query with the help of any of the given solutions or do you still need more help here? Do let us know.
Thanks!

Sukrity Wadhwa