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: 
sibrulotte
Creator III
Creator III

Partial sum of rounding

Hi,

have any of you come across this:

(sum({$<[%CLE_Type_Transaction_ID] -= {'EB', 'EA'}, [Numéro du type d'écriture] -= {'FERM'} >}[Montant cumulé aad]* %CR003M))

This returns a two decimal number.

When I wrap it with round, I get a rounded number.

Unfortunatly, the partial sum didn't get the memo...

It still treats the numbers as two decimals, and returns a rounded number that is off.

See my jpgs for as an exemple.

1 Solution

Accepted Solutions
jerem1234
Specialist II
Specialist II

You'll have to create two sums, one for regular values and another for your partial sums. I've attached an example qvw. I used a formula like:

if(dimensionality() =2, round(sum(Value)), sum(aggr(round(sum(Value)), Type, Product)))

You should be able to accommodate this formula to your fields and calculations. The important parts are dimensionality() to distinguish between the regular values and your partial sums (the 2 may change depending on how much aggregation you are doing) and  sum(aggr()) to sum the required rounded values (the fields listed will be dependent on your data).

EDIT: You may actually be able to get away with just:

sum(aggr(round(sum(Value)), Type, Product))

Hope this helps!

View solution in original post

12 Replies
Not applicable

I dont quite understand the issue. The subtotal is rounded off from 360381431,61 to 360 381 432

since the decimal place is 61 (>50) its rounded.

if num is 1.5 will be rounded to 2

if              1.8  will be 2

if             1.4 will be 1.

Can you explain a little more or am I missing something?

Note: if you just wanna drop the decimal part without rounding you can try floor().

sibrulotte
Creator III
Creator III
Author

Look at the rounded numbers:

58 668 858 + 302 752 512 - 1 039 939 = 360 381 431 NOT 360 381 432

Sorry for the long digits, I just gave you the precises numbers.

So the partial sum is still using the unrounded numbers. It's driving me crazy.

ashwanin
Specialist
Specialist

Which qv version you are using.

because what i know is that the qv automatically do the same thing as Ajay wrote ie. it auto convert the last digits to the above value .

This happens when you have the long decimal digits.

ashwanin
Specialist
Specialist

and sometimes lowers the value ,as per the last digit (ie below 4)

Not applicable

I see what you are getting to but qlikview doesn't add the rounded off numbers. It adds the actual numbers and rounds off the result.

But as you mentioned it is misleading. This is interesting..

sibrulotte
Creator III
Creator III
Author

So rounding tlike this worked:

(sum({$<[%CLE_Type_Transaction_ID] -= {'EB', 'EA'}, [Numéro du type d'écriture] -= {'FERM'} >}round([Montant cumulé aad])* %CR003M))

sibrulotte
Creator III
Creator III
Author

SO I am taking out the correct answer that I had put to my own self...

hehe.

This is horrendous and skews the results since obviously every single line behind the code is rounded, creating havoc in my results.

So I am back to complaining that the partial sum doesn't get that the results are rounded, and takes the unrounded values to show a rounded sum.

I'm using QV 11 SR2

jerem1234
Specialist II
Specialist II

You'll have to create two sums, one for regular values and another for your partial sums. I've attached an example qvw. I used a formula like:

if(dimensionality() =2, round(sum(Value)), sum(aggr(round(sum(Value)), Type, Product)))

You should be able to accommodate this formula to your fields and calculations. The important parts are dimensionality() to distinguish between the regular values and your partial sums (the 2 may change depending on how much aggregation you are doing) and  sum(aggr()) to sum the required rounded values (the fields listed will be dependent on your data).

EDIT: You may actually be able to get away with just:

sum(aggr(round(sum(Value)), Type, Product))

Hope this helps!

sibrulotte
Creator III
Creator III
Author

Well that definitly seems to work in your file.

You have no idea how much coding time this will require though for me. :*(