Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Attend QlikWorld 2020 and hear keynote speaker, Malcolm Gladwell. $300 savings extended to February 9th Learn More
Highlighted
berryandcherry6
Contributor II

Fetching Sum of rows of a table in Script

Hi,

I have a table as shown below

fruitID    fruitvalue

1              3

1               4

2               5

2               7

3                9

3              4

1               8

1               9



Now i need to create a table in script(Load editor) such a way that,it has give sum of fruitvalue for each fruitID

fruitID    fruitvalue

1              24

2               12

3                13

I do know that, using table by dimension:fruitID &&  Expression: fruitvalue i can achieve this,but i need to get from scripting itself like it has to loop for specific fruitIDs and get sum of those.

IS it possible?if  not, Could please share reason for this

if yes, How could i do this? Any ideas, suggestion is helpful

Tags (2)
2 Replies
simotrab
Contributor III

Re: Fetching Sum of rows of a table in Script

Hi!

You could do something like

fruits:

load

fruitID,

sum(value)

inline

[fruitID,value

1,3

1,4

2,5

2,7

3,9

3,4

1,8

1,9

]

group by fruitID

;

if it is a load inline.

Clearly you can decline it also to a sql select or other things.

you can also do something like

fruits:

load*inline

[fruitID,value

1,3

1,4

2,5

2,7

3,9

3,4

1,8

1,9

]

;

STORE fruits INTO [lib://yourdirectory/fruit.qvd] (qvd);

fruits2:

load

fruitID,

sum(value)

from [lib://yourdirectory/fruit.qvd] (qvd)

group by fruitID;


  Drop Table fruits;


to do not have a table that could be useless.

MVP & Luminary
MVP & Luminary

Re: Fetching Sum of rows of a table in Script

Hi,

Try like this

Data:

LOAD

*

FROM DataSource;

LEFT JOIN(Data)

LOAD

FruitID,

Sum(value) AS TotalFruitvalue

RESIDENT Data

GROUP BY FruitID;

Regards,

Jagan.