Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

magnusrydberg
New Contributor II

Error when using SUM and GROUP BY in sqript

I am running this sqript using SUM and GROUP BY function in a load statement:

LOAD

    StringKey1 as ContLONumber,

    StringKey4 as ContSequence,

    Status as ContStatus,

    Sum("Time") as ContLogTime

    Group By StringKey1;

    SQL SELECT * FROM "MyL_PROD_220".OTSDATA.TimeLog where StringKey6='CONT';

When executing the sqript I'll got the error message "invalid expression"

What is not correct in my sqript?

1 Solution

Accepted Solutions
MVP
MVP

Re: Error when using SUM and GROUP BY in sqript

If you use a Group By, ALL the non-aggregated fields must be in the Group By list. So this should work

LOAD

    StringKey1 as ContLONumber,

    StringKey4 as ContSequence,

    Status as ContStatus,

    Sum("Time") as ContLogTime

    Group By StringKey1, StringKey4, Status;

SQL SELECT * FROM "MyL_PROD_220".OTSDATA.TimeLog where StringKey6='CONT';

2 Replies
MVP
MVP

Re: Error when using SUM and GROUP BY in sqript

If you use a Group By, ALL the non-aggregated fields must be in the Group By list. So this should work

LOAD

    StringKey1 as ContLONumber,

    StringKey4 as ContSequence,

    Status as ContStatus,

    Sum("Time") as ContLogTime

    Group By StringKey1, StringKey4, Status;

SQL SELECT * FROM "MyL_PROD_220".OTSDATA.TimeLog where StringKey6='CONT';

magnusrydberg
New Contributor II

Re: Error when using SUM and GROUP BY in sqript

Thanks a lot Jonathan! Now it works and I understand the "Group By" statement