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: 
AndreasMoller
Contributor III
Contributor III

Mark Valids orders from ID-column with latest Date

Hello

I have a table that looks something like this: 

ID Order Date
1 12345 2023-05-15
2 23456 2023-05-14
2 45666 2023-05-13
3 34225 2023-05-14

 

I want to mark the latest distinct value from ID as valid, so i want the result to look something like this:

ID Order Date Valid
1 12345 2023-05-15 1
2 23456 2023-05-14 1
2 45666 2023-05-13 0
3 34225 2023-05-14 1

 

Row 3 have the same ID as Row 2 and Row 3 is older then Row 2, thats why i want valid to be 0 on Row 2. 

Can anyone help me?  Thanks!

Labels (2)
1 Solution

Accepted Solutions
Kushal_Chawda

@AndreasMoller  try below

Data:
Load ID,
     Order,
     Date
FROM Source;

New:
Load *,
     if(ID=Previous(ID),0,1) as Valid
Resident Data
Order by ID, Date desc;

Drop Table Data;

View solution in original post

2 Replies
Kushal_Chawda

@AndreasMoller  try below

Data:
Load ID,
     Order,
     Date
FROM Source;

New:
Load *,
     if(ID=Previous(ID),0,1) as Valid
Resident Data
Order by ID, Date desc;

Drop Table Data;
AndreasMoller
Contributor III
Contributor III
Author

That will do it, thank you!