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: 
Not applicable

Using aggregation funuctions in Script

i am using sum and count functions in my script, but it gives me error like invalid functions. So i just want to know is,  can use use these functions in script and if yes then can some one share some syntax of  using them with an if statement.

1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

Hi,

Elaborating a bit on what Marc aptly suggests, the script should look like the following:

AllData_Temp:

LOAD Country,

     CustomerID,

     Value,

     Discount,

     NewCustomer

FROM Customers.qvd (qvd); // or whatever other data source here

// Sum and Count when NewCustomer = 1

AggregatedData:

LOAD Country,

     Sum(If(NewCustomer = 1, Value, 0)) AS CountryValue,

     Sum(If(NewCustomer = 1, Discount, 0)) AS CountryDiscount

RESIDENT AllData_Temp

GROUP BY Country;

DROP TABLE AllData_Temp;

Hope that helps.

Miguel

View solution in original post

5 Replies
Not applicable
Author

you can, but you need to do a group by with a resident table.

Miguel_Angel_Baeyens

Hi,

Elaborating a bit on what Marc aptly suggests, the script should look like the following:

AllData_Temp:

LOAD Country,

     CustomerID,

     Value,

     Discount,

     NewCustomer

FROM Customers.qvd (qvd); // or whatever other data source here

// Sum and Count when NewCustomer = 1

AggregatedData:

LOAD Country,

     Sum(If(NewCustomer = 1, Value, 0)) AS CountryValue,

     Sum(If(NewCustomer = 1, Discount, 0)) AS CountryDiscount

RESIDENT AllData_Temp

GROUP BY Country;

DROP TABLE AllData_Temp;

Hope that helps.

Miguel

Not applicable
Author

Works perfectly. Please mark it as answers so others can benefit....

evan_kurowski
Specialist
Specialist

As an addition to this.. if all you are requesting are aggregation expression results, no group by or dimension fields are required.

Data_Range:

LOAD

     Min(Date) AS Earliest_Data_Date

      ,Max(Date) AS Latest_Data_Date

RESIDENT Fact_Table;

Anonymous
Not applicable
Author

The post on this thread from Evan Kurowski was accidentally. In order to restore points to all participants I have copied and reinserted this comment. Thanks for your patience!