Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Script to load the first sorted instance of a record

Hi guys,

I am trying to figure out a way to load the first instance of duplicated data in my script. I will then use this data to join to another set of data.

e.g,

CustomerCummulative SumDate
a5028/12/14
a4020/12/14
a3017/12/14
a2015/12/14
a1001/12/14

So I want only one instance of customer a which would be the latest sorted date where sum would equal to 50 and data would be 28/12/14.

I think in Teradata, I would have the following at the end of my SQL

qualify rownumber() over( partition by customer, cummulative order by date)=1

4 Replies
msteedle
Luminary Alumni
Luminary Alumni

FirstSortedValue is an aggregation function you can use in the script to do just this, grouped by Customer, in your example. The example in the QV Desktop help for that function is very similar to what you are doing.

Anonymous
Not applicable
Author

Thanks for the reply, so basically, I need to have this function at every column that I don't group with

msteedle
Luminary Alumni
Luminary Alumni

As with all aggregating in the script, any expression not in the GROUP BY requires some aggregation function.

An alternative would be breaking it into multiple steps, like loading the original table, then doing a resident load with ORDER BY and use an inter record functions like Peek to create an indicator or flag on the latest row per customer. Lastly you can do a resident load of that table WHERE the indicator or flag value is for the latest row, or just inner join an inline table containing only the desired flag or indicator value.

Anonymous
Not applicable
Author

Make sense, will give this a shot, thanks