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: 
Raju_6952
Creator II
Creator II

issue with Sum(Value)

Hi,

I have value field coming from excel file and sum(value) is giving wrong value. any idea why the sum(value) is wrong here. I am using measure like sum(value) not used any set analysis.

Raju_6952_0-1704792297980.png

 

Thanks in advance,

 

Labels (2)
10 Replies
P_Kale
Creator II
Creator II

Hi,

What values do you have in excel. Pl share the file

Or
MVP
MVP

Presumably, what you're showing as "one row" is actually 431 rows of data with the same unique dimension combination. You should be able to confirm this by adding e.g. Count(Value) as a measure.

Raju_6952
Creator II
Creator II
Author

Hi @Or ,

Yes count(Value) is 431 only, any idea to make it work .

Or
MVP
MVP

Fix whatever is causing the duplication in the data model, or don't use sum(), or use aggr() in some way to get around whatever is wrong with the data model. Impossible to say without knowing what the data model is like.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Since all 431 rows have the same value for "Value", I assume you could use Sum(Distinct Value). 

As @Or suggested, you may want to investigate the duplication in the data model to determine if it's valid.

-Rob

Raju_6952
Creator II
Creator II
Author

Hi @rwunderlich ,

Thanks for the update, I used distinct to remove the duplicates.

 

Regards,

Raju

Or
MVP
MVP

Sum(Distinct) is almost never a good idea. For example, consider that in the below dataset, the sum of A will be 3, the sum of B will be 5, and the total sum distinct will be 6 rather than 8.

Dim1, Value

A, 1

A, 2

B, 2

B, 3

I'd strongly advise either fixing the data model or, if that's not feasible for some reason, working with aggr(). Sum(Distinct) is (almost) never the answer.

Raju_6952
Creator II
Creator II
Author

the problem is that on the source side data is loaded twice or thrice with similar data as follows.

Raju_6952_0-1704888391530.png

need to consider only value for latest modified date for each primary key field.

 

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Then I would suggest something like:

Sum(Aggr(FirstSortedValue(Value, -ModifedDate), PrimaryKey))

Not sure if you will need "NoDistinct" in the Aggr(). Didn't get a chance to test it. 

-Rob