BI Quest [A blog on Informatica]

Share what you learn

Archive for the ‘Scenario Based Questions’ Category

Loading Top/Bottom N records in target

Posted by Ankur Nigam on March 3, 2013

I ran into a problem again. This time the requirement was not from BOSS but a scenario which often I see in the blogs. One of it is loading Top/Bottom N records in the target. People present different solution for each of them. I took it a little further and tried to develop a mapping which can load Top or Bottom record, depending upon the value passed. Let’s say for example it is required to load top 3 records then the parameter value would be 3 or it would be -3 in case of loading bottom records. The information will be parameterized to enable full flexibility.

Screenshot-2013-03-03_16.28.13

My mapping looks something like this:-

Screenshot-2013-03-03_16.32.59

In a nutshell I will explain what I have done:-

Step 1 : Read records
Step 2 : Sequence them
Step 3 : In a router create two groups ; $$LoadTill > 0 (First Records) and $$LoadTill < 0 (Bottom Records)
Step 4 : Sort all the rows from group First Records in Ascending manner
Step 5 : Sort all the rows from group Last Records in Descending manner
(Below steps are common for all the abovemntioned groups)
Step 6 : Pass the records from Sorter to Expression transformation and generate a sequence number using variable port
Step 7 : In the same expression deduce whether this record is eligible to be written to target
Step 8 : Load target, only if the record counter is same or less than $$LoadTill

Posted in Informatica, Scenario Based Questions | Leave a Comment »