Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
jduluc12
Creator
Creator

firstsortedvalue, aggr and valuelist

Hi,

I have two tables

Table_1:

ItemID1AMT1ID2AMT2Relation
Item_1ID1_12ID2_131
Item_2ID1_220ID2_2562
      

 

Table_2:

ID2AMTID3Num
ID2_12ID3_11
ID2_120ID3_22
ID2_250ID3_33

 

the desired pivot table is 

ItemRelationTypeAMT 
Item_11SO2 
  IN4 
  Rcv12 
  Rcv220 
Item_22SO20 
  IN56 
  Rcv150 

 

Dimension:

  1. Item
  2. ValueList('SO',  'IN, 'Rcv1', 'Rcv2)

Expression:

if(ValueList('SO', 'IN', 'Rcv1', 'Rcv2') = 'SO', only(AMT1),
if (ValueList('SO', 'IN', 'Rcv1', 'Rcv2') = 'IN', only(AMT2),
if (ValueList('SO', 'IN', 'Rcv1', 'Rcv2') = 'Rcv1',
FirstSortedValue( aggr( NODISTINCT SUM(Table2.AMT), Table1.Item, Table1.Relation, Table2.ID3), Table2.Num,1),

FirstSortedValue( aggr( NODISTINCT SUM(Table2.AMT), Table1.Item, Table1.Relation, Table2.ID3), Table2.Num,2),
)))

 

the issue is the firstsortedvalue (). It returns nothing.

if I just use the aggr without the firstsortedvalue then I get values but I can not separate the Rcv1 from Rcv2.

what am I missing here?

 

 

Labels (1)
1 Reply
jduluc12
Creator
Creator
Author

FirstSortedValue( DISTINCT aggr( NODISTINCT SUM(Table2.AMT), Table1.Item, Table1.Relation, Table2.ID3), Table2.Num,2)

Adding DISTINCT did the trick.