Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
berryandcherry6
Creator II
Creator 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

2 Replies
simotrab
Creator III
Creator III

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.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

Data:

LOAD

*

FROM DataSource;

LEFT JOIN(Data)

LOAD

FruitID,

Sum(value) AS TotalFruitvalue

RESIDENT Data

GROUP BY FruitID;

Regards,

Jagan.