Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
Qlik Connect 2025! Where innovative solutions turn your data visions into reality: REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
govindvasu
Contributor III
Contributor III

Sum() in load script

Hi,

I am trying to implement sum functionality in the data load editor, when loading the data it is throwing the invalid expression error. 

Here is the script i am running

Data_total:

load

     emp_id,

     key,

    amount,

     sum(amount) as Sum_amount

resident Data

where Key = 0

and Date >= addmonths(today(), -12)

group by emp_id;

 

 

 

Labels (4)
1 Solution

Accepted Solutions
cristianj23a
Partner - Creator III
Partner - Creator III

It happens that you are adding the "Name" field, if you want to use the Name then add it to the GROUP BY.

Temp:
LOAD
ID,
Name,
"Give yourself",
"Money(Amount)"

FROM [Book1.xlsx]
(ooxml, embedded labels, table is Sheet2);

 

sum:
LOAD ID, //Replace the ID
Name,
Sum("Money(Amount)") as MySum
Resident Temp
Where Year("Date")>2017
Group By ID, Name;

 

About the Money field, it's better to remove $ and format it in the chart.

 

https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.

View solution in original post

10 Replies
BrunPierre
Partner - Master
Partner - Master

Hi, You need to include all fields within the GROUP BY clause that are not aggregated or another way could be this.

Data_total:
LOAD
emp_id,
Only(key) as key,
Only(amount) as amount,
sum(amount) as Sum_amount
RESIDENT Data
WHERE Key = 0 AND Date >= Date(addmonths(today(), -12),'YourFormat')
GROUP BY emp_id;

cristianj23a
Partner - Creator III
Partner - Creator III

try this code.

 

Where Year(Date)>'2017';

Don't forget that your "Date" field is in 'DD/MM/YYYY' format, you must change it to Year so you can filter.

https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.
govindvasu
Contributor III
Contributor III
Author

Tried this still showing as invalid expression. I Just tried only the sum() ,groupby clause on emp_id still showing as invalid expression. Is there any specific article for implementing the Sum()?
Appreciate your help !

govindvasu
Contributor III
Contributor III
Author

Tried this still throwing invalid expression. I think i am doing something wrong in the sum function

appreciate your help!

cristianj23a
Partner - Creator III
Partner - Creator III

Please send me the full code you are using and a screenshot of the error message.
To be able to help you.

https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.
govindvasu
Contributor III
Contributor III
Author

Here is the code of data load editor in qliksense,
Temp:
LOAD
    ID,
    Name,
    "Date",
    "Money(Amount)"
     
FROM [Book1.xlsx]
(ooxml, embedded labels, table is Sheet2);
 
Sum:
 
LOAD Name, 
Sum("Money(Amount)") as MySum 
Resident Temp 
Where Year("Date")>2017
Group By  ID;
 
Here is the screenshot of the error
govindvasu_0-1691079564059.png

 


 

cristianj23a
Partner - Creator III
Partner - Creator III

Hol, it happens that in your GROUP BY you are putting the ID field, when in your load it does not exist.

Temp:
LOAD
ID,
Yam,
"Give yourself",
"Money(Amount)"

FROM [Book1.xlsx]
(ooxml, embedded labels, table is Sheet2);

sum:
LOAD ID, //Replace the ID
Sum("Money(Amount)") as MySum
Resident Temp
Where Year("Date")>2017
Group By ID;

https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.
govindvasu
Contributor III
Contributor III
Author

Updated my Load statement, still the same.

govindvasu_0-1691080063704.png

is this something related to type of fields?
I am doubting the field " Money(Amount)" sample of data in field " Money(Amount)" is below

$500.00
$200.00
$200.00
$250.00
cristianj23a
Partner - Creator III
Partner - Creator III

It happens that you are adding the "Name" field, if you want to use the Name then add it to the GROUP BY.

Temp:
LOAD
ID,
Name,
"Give yourself",
"Money(Amount)"

FROM [Book1.xlsx]
(ooxml, embedded labels, table is Sheet2);

 

sum:
LOAD ID, //Replace the ID
Name,
Sum("Money(Amount)") as MySum
Resident Temp
Where Year("Date")>2017
Group By ID, Name;

 

About the Money field, it's better to remove $ and format it in the chart.

 

https://www.linkedin.com/in/cristianjorge/
Do not forget to mark as "Accepted Solution" the comment that resolves the doubt.