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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

group by order by

1) what's wrong with this statement. I keep getting expression error.

table:

LOAD ActNo,

count(ActNo) as Uniq,  

firstname,

lastname,

expyear,

expmonth,

expday

from a qvd       

GROUP BY ActNo order by ActNo, expmonth, expyear desc;

2) if I am just looking into grouping by something without actually doing any aggregation how can I perform group by and then order by.

16 Replies
maxgro
MVP
MVP

1)

you have to add to group by all fields excluding

count(ActNo) as Uniq, 


and you have to remove order by

2)

when you group, all fields not in group by need an aggregation function

ashfaq_haseeb
Champion III
Champion III

Groupby will not work on qvd.

You have ti try like this

Temp:

LOAD ActNo,

firstname,

lastname,

expyear,

expmonth,

expday

from a qvd  ;

   

Main

LOAD

ActNo,

count(ActNo) as Uniq, 

only(firstname) as firstname,

only(lastname) as lastname,

only(expyear) as expyear,

only(expmonth) as expmonth,

only(expday) as expday

resident Temp

GROUP BY ActNo;

drop table Temp;


Regards

ASHFAQ

robert99
Specialist III
Specialist III

So this would be required I think

table:

LOAD ActNo,

//count(ActNo) as Uniq,

firstname,

lastname,

expyear,

expmonth,

expday

from a qvd  ; 


table2:

noconcatenate

LOAD ActNo,

//count(ActNo) as Uniq,

firstname,

lastname,

expyear,

expmonth,

expday

resident table

order by ActNo, expmonth, expyear desc; (order descending?)

drop table;

table2:

join table2 //if required

LOAD ActNo,

count(ActNo) as Uniq

resident  table2   

GROUP BY ActNo;

Anonymous
Not applicable
Author

Hi,

The count function is not valid  for the script.

regards!

Not applicable
Author

then whats wrong with this statement.

temp:

LOAD

  ActNo,

firstname,

lastname,

  year,

  month

FROM

qvd

order by ActNo,year desc;

robert99
Specialist III
Specialist III

order by can only be done from a resident load (I think)

ashfaq_haseeb
Champion III
Champion III

Check my reply

maxgro
MVP
MVP

remove order by, you can only use order by in a resident load, not in a load from a qvd

temp:

LOAD

  ActNo,

firstname,

lastname,

  year,

  month

FROM

qvd

Not applicable
Author

Thanks everyone. I got it to work but not getting results i want. Here is my data and what i require.

AcctNo     Orderdate         Expdate               item

123           18-02-2014       21-02-2015            5

128            4-5-2014            6-6-2015              32

125            20-02-2014       4-4-2015                 7

123            21-03-2014     21-02-2015             5

125            18-05-2014       4-4-2015                 7

128            2-2-2014           5-3-2015               21

how can i load above data sort in such a way where it will only pick records with latest ord & latest exp date.

answer for above will be

AcctNo     Orderdate         Expdate               item

123           18-02-2014       21-02-2015            5

125            18-05-2014       4-4-2015               7

128            4-5-2014            6-6-2015              32