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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
mansoorsheraz
Creator
Creator

Load only one row for a group/set of data

Hi,

I have the following data:

mansoorsheraz_0-1663874478791.png

You can see abc.com and def.com have posted with two book numbers rest of the two domains have only one. I want the result set to be like this:

mansoorsheraz_1-1663874561780.png

 

So that if there are duplicate book numbers, it should pick up the one with the latest one. I have tried to do this using concatenation but I dont think so that is the right approach as I may miss on something. Can someone let me know how to get the resultant table with the best way?

Labels (3)
5 Replies
BrunPierre
Partner - Master II
Partner - Master II

As below

 

TempDataTable:
LOAD * Inline[
Domain,Date Reported Value,UOM,Quarters,Book Number,Value,Head
abc.com,2020-12-31,4,PKR, pk-2020,350000,Net Income
abc.com,2020-12-31,4,PKR, pk-2021,350000,Net Income
xyz.com,2020-12-31,4,PKR, pk-2020,225000,Net Income
def.com,2020-12-31,4,PKR, pk-2020,675000,Net Income
def.com,2020-12-31,4,PKR, pk-2021,675000,Net Income
qwe.com,2020-12-31,4,PKR, pk-2021,9800  ,Net Income

];

NoConcatenate
FinalDataTable:
LOAD Domain,
[Date Reported Value],
UOM,
Quarters,
Value,
Head,
LastValue([Book Number]) AS [Book Number]

Resident TempDataTable
Group by Domain,[Date Reported Value],UOM,Quarters,Value,Head;

DROP Table TempDataTable;

 

RafaelBarrios
Partner - Specialist
Partner - Specialist

Hi @BrunPierre 

Like the approach from @BrunPierre, it will depende on how you receive the data,

I would suggest the exact same script but with 

maxstring([Book Number]) as [Book Number]

Best,

 

mansoorsheraz
Creator
Creator
Author

Thanks for your help, this approach will also have the double load, can't this be done in a single load?

BrunPierre
Partner - Master II
Partner - Master II

Try this front-end expression.

=FirstSortedValue(Value,-Aggr(Sum(Value),Domain),1)

RafaelBarrios
Partner - Specialist
Partner - Specialist

So, try preceding load

I stole the example from  @BrunPierre  that comes in handy for a quick test

FinalDataTable:
LOAD
   Domain,
   [Date Reported Value],
   UOM,
   Quarters,
   Value,
   Head,
   LastValue([Book Number]) AS [Book Number],
  maxstring([Book Number]) AS [Book Number2]
Group by Domain,[Date Reported Value],UOM,Quarters,Value,Head;
LOAD * Inline [
   Domain,Date Reported Value,UOM,Quarters,Book Number,Value,Head
   abc.com,2020-12-31,4,PKR, pk-2020,350000,Net Income
   abc.com,2020-12-31,4,PKR, pk-2021,350000,Net Income
   xyz.com,2020-12-31,4,PKR, pk-2020,225000,Net Income
   def.com,2020-12-31,4,PKR, pk-2020,675000,Net Income
   def.com,2020-12-31,4,PKR, pk-2021,675000,Net Income
   qwe.com,2020-12-31,4,PKR, pk-2021,9800 ,Net Income];

 

Best,