Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
mazacini
Creator III
Creator III

create new fields based on combination of existing data, BUT NOT USING IF

   

ItemTypeAreaRepNewRep
1234TypeANorthJohnJohn
1235TypeASouthFrankFrank
1236TypeBEastSarahSarah
1237TypeCNorthJohnJohn
1238TypeCEastSarahSarah
1239TypeDNorthJohnFrank
1240TypeBNorthJohnSarah

I have a table (Table A) with fields Item, Type, Area and Rep.

Item is a unique ID.

I want to append a new field NewRep, based on following rules:

1. If Type B is sold in North, Change Rep to Sarah;
2. Change Type D to Frank;
3, All Others - New Rep same as Rep;

I do not want to use an if statement in the load as there are actually more rules applying to the actual data.

I have tried to create a new table with the new field based on resident loads with "Where" conditions for Rules 1 & 2. But I am trying to figure out how to load all other data NOT covered by Rules 1 & 2.

Script (rough synatax) -

TableB:

Load *,

'Sarah as NewRep

resident TableA

where Type = TypeB and Area  = North;

Load *,

'Frank' as NewRep

resident TableA

where Type = TypeD;

This is where I have a problem

My idea was to use the Item field to identify which records had not yet been appended to Table B

So the script would do the following:

Where the Item has not been loaded to TableB,, load the records from TableA. and create the NewRep field using the Rep field for these records.

Any ideas?

1 Solution

Accepted Solutions
swuehl
MVP
MVP

If you want to do it that way maybe like

TableB:

Load *,

'Sarah as NewRep,

Item as Item2

resident TableA

where Type = TypeB and Area  = North;

Load *,

'Frank' as NewRep,

Item as Item2

resident TableA

where Type = TypeD;

Concatenate LOAD *,

Rep as NewRep,

Resident TableA

Where not exists(Item2, Item);

drop field Item2;

View solution in original post

3 Replies
swuehl
MVP
MVP

If you want to do it that way maybe like

TableB:

Load *,

'Sarah as NewRep,

Item as Item2

resident TableA

where Type = TypeB and Area  = North;

Load *,

'Frank' as NewRep,

Item as Item2

resident TableA

where Type = TypeD;

Concatenate LOAD *,

Rep as NewRep,

Resident TableA

Where not exists(Item2, Item);

drop field Item2;

mazacini
Creator III
Creator III
Author

Thanks. Will test in the morning.

Do I not need to load Item2 in the Concatenate load statement?

Thank ylu.

mazacini
Creator III
Creator III
Author

That worked fine. Thank you.

For future readers, I would add that you also need to drop Table A at the

end.