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

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
LoKi_asterix
Contributor III
Contributor III

Get last transaction attributes issue with FirstSortedValue

Hey everyone, I’m running with this syntax, but I’ve run into a snag. A few records share the same date time, which leaves their Ref, Sales, and Narration fields showing up as null. The system does generate a Recid in the format 177980236362379.000001, but the tricky part is that the Recid values aren’t consistent one of them happens to be 177980236362379.000001. Is there another way around this? And if not, how can I make better use of the Recid field

Last_Transactions:
LOAD CustID,
Customer,
FirstSortedValue(Ref, -[DATE TIME]) as Ref,
FirstSortedValue(Sales, -[DATE TIME]) as Sales,
FirstSortedValue(Narration, -[DATE TIME]) as Narration,
Max([DATE TIME]) as [DATE TIME],
Max([Value Date]) as [Value Date]
RESIDENT Temp_Transactions
GROUP BY CustID, Customer;

3 Replies
Or
MVP
MVP

I tried wrapping my head around the question, but couldn't quite follow. If you have an ID column, why not use that for your FirstSorted sort? 

LoKi_asterix
Contributor III
Contributor III
Author

After presorting the dataset, I applied FirstValue(), and it returned the expected result.

marcus_sommer

The aggregation might be outsourced - maybe in this way:

Last_Transactions:
LOAD CustID,
Customer,
Ref,
Sales,
Narration,
[DATE TIME]
RESIDENT Temp_Transactions;

inner join(Last_Transactions)
LOAD CustID,
Customer,
Max([DATE TIME]) as [DATE TIME],
Max([Value Date]) as [Value Date]
RESIDENT Temp_Transactions
GROUP BY CustID, Customer;

Another approach could be to use interrecord-functions like peek() and previous() within an appropriated sorted resident-load and comparing the values from the current record against the previous ones and then flagging the records. It avoids to handle (n) aggregation tables and provides extra possibilities in regard to calculate offsets between the records and/or to accumulate them.