Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Group BY

Hi,

I am trying to do group by but its giving me an error . Appreciate any help on this . Please find attached Qvw and Excel spreadsheet

Data_Temp:

LOAD Country,

     Year,

     Sales,

   if(Country = 'INDIA',Sales) as IndiaSales,

     ISSUES,

     RETURNS,

     ISSUES - RETURNS as Adjustments

FROM

GroupBY.xlsx

(ooxml, embedded labels, table is Sheet1);

Data:

LOAD

     Country,

     Year,

     Sales,

     IndiaSales,

     ISSUES,

     RETURNS,

     SUM (Adjustments) as  Adjustments

     Resident Data_Temp

     Group by Country;

DROP Table Data_Temp;

EXIT Script;

1 Solution

Accepted Solutions
jagan
Luminary Alumni
Luminary Alumni

Hi,

You need to specify all the fields in the Group by clause, if you want to use Aggregate functions in Load statement, so your query should be

Data_Temp:

LOAD Country,

     Year,

     Sales,

   if(Country = 'INDIA',Sales) as IndiaSales,

     ISSUES,

     RETURNS,

     ISSUES - RETURNS as Adjustments 

FROM

GroupBY.xlsx

(ooxml, embedded labels, table is Sheet1);

Data:

LOAD

     Country,

     Year,

     Sales,

     IndiaSales,

     ISSUES,

     RETURNS,

     SUM (Adjustments) as  Adjustments

Resident Data_Temp

Group by Country,

     Year,  

     Sales,

     IndiaSales,

     ISSUES,

     RETURNS;

DROP Table Data_Temp;

OR if you want Count level adjustments then use like this

Data_Temp:

LOAD Country,

     Year,

     Sales,

   if(Country = 'INDIA',Sales) as IndiaSales,

     ISSUES,

     RETURNS,

     ISSUES - RETURNS as Adjustments 

FROM

GroupBY.xlsx

(ooxml, embedded labels, table is Sheet1);

Data:

LOAD

     Country,

          SUM (Adjustments) as  Adjustments

Resident Data_Temp

Group by Country;

    

DROP Table Data_Temp;

Hope this helps you.

Regards,

Jagan.

View solution in original post

4 Replies
sujeetsingh
Master III
Master III

See the sample

Kushal_Chawda

You are doing group on only one column whereas you have not included other columns in the group.

Use below script

Data_Temp:

LOAD Country,

     Year,

     Sales,

   if(Country = 'INDIA',Sales) as IndiaSales,

     ISSUES,

     RETURNS,

     ISSUES - RETURNS as Adjustments

FROM

GroupBY.xlsx

(ooxml, embedded labels, table is Sheet1);

Data:

LOAD

     Country,

     Year,

     Sales,

     IndiaSales,

     ISSUES,

     RETURNS,

     SUM (Adjustments) as  Adjustments

     Resident Data_Temp

     Group by Country,

     Year,

     Sales,

     IndiaSales,

     ISSUES,

     RETURNS

;

DROP Table Data_Temp;

EXIT Script;

jagan
Luminary Alumni
Luminary Alumni

Hi,

You need to specify all the fields in the Group by clause, if you want to use Aggregate functions in Load statement, so your query should be

Data_Temp:

LOAD Country,

     Year,

     Sales,

   if(Country = 'INDIA',Sales) as IndiaSales,

     ISSUES,

     RETURNS,

     ISSUES - RETURNS as Adjustments 

FROM

GroupBY.xlsx

(ooxml, embedded labels, table is Sheet1);

Data:

LOAD

     Country,

     Year,

     Sales,

     IndiaSales,

     ISSUES,

     RETURNS,

     SUM (Adjustments) as  Adjustments

Resident Data_Temp

Group by Country,

     Year,  

     Sales,

     IndiaSales,

     ISSUES,

     RETURNS;

DROP Table Data_Temp;

OR if you want Count level adjustments then use like this

Data_Temp:

LOAD Country,

     Year,

     Sales,

   if(Country = 'INDIA',Sales) as IndiaSales,

     ISSUES,

     RETURNS,

     ISSUES - RETURNS as Adjustments 

FROM

GroupBY.xlsx

(ooxml, embedded labels, table is Sheet1);

Data:

LOAD

     Country,

          SUM (Adjustments) as  Adjustments

Resident Data_Temp

Group by Country;

    

DROP Table Data_Temp;

Hope this helps you.

Regards,

Jagan.

sujeetsingh
Master III
Master III

Jagan it is a helpful one .