Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Partial sum in a table

Hi to all,

I have a problem to calculate a partial sum in a simple table. I need to sum (for example) the first 3 values, excluding the last 2.

The table is:

1st col. id

2nd col tariffa

ID TARIFFA

160 1534,56

160 1534,56

160 754,90

160 1534,56

160 1534,56

I'm trying in any way (RANGESUM, ABOVE etc.), but I can't reach my target.

I would have my sum as 3824,02 (1534,56+1534,56+754,90) instead of total sum 6893,14.

Please help me. Thank you.

13 Replies
Not applicable
Author

Thnx to all, the solution posted by Eugene ia able to sum first 3 values......but the table data to analyze is more complicated Stick out tongue and the number of values that I have to sum changes every time in reason of the ID number.

So in the script the number three shoudn't be a constant but a variable calculated dynamically for any kind of ID.

Maybe a faster solution is to number every record from 1 to n for every kind of ID:

160 1

160 2

160 3

135 1

135 2

120 1

120 2

160 4

120 3

etc . , so I could sum the first X values for every kind of ID.

I hope I was able to explain it clearly. Sad

Not applicable
Author

Is there a forumla that calculates the count of records to sum based on ID, or is it more like a different number for each ID, with no pattern? In the second case the solution would be a seperate mapping table. Let me know, and I can show you how I would do it.

Not applicable
Author

I have a formula like this as an expression of my graph table:

Count( IF( CONDITION, ID) )

that count how many IDs are admissible (for each kind of ID) so this is equal to maxiumu number of ID admitted to calculate sum, even if in the table I have more IDs.

So for every kind of ID i have a limit in summing values.



Not applicable
Author

I would use a formula like the one you included in your post, not in the dimension, but instead inside an aggr function which would be the third argument to this "top" function:

rangesum

(top( TARIFFA,1,3))

The dimension for the aggr function would likely be ID. If you need more help attach your qvw with some notes.