

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sum(A) + Sum(B) or Sum(A+B)
Hi,
a quick one, where I´m uncertain:
I simply want to sum up two fields inculding (same) set analysis. Normally I do it in this way:
sum( {<[Date.Cal.Year]={2017}>} [FieldA]) + sum( {<[Date.Cal.Year]={2017}>} [FieldB])
Now I saw that this also works:
sum( {<[Date.Cal.Year]={2017}>} ([FieldA] + [FieldB]))
FieldA and FieldB are both from the same (facts) table.
Due to I have a very large data set and complex nested formulas I´d prefer the second version, but I´m uncertain if there could be any differences in the result.
Can anybody confirm whether the two versions are identical or otherwise outline the difference?
Thanks, Thomas
- « Previous Replies
- Next Replies »

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
i think the second solution is bester
but if FieldA and FieldB are both from the same (facts) table you can pre caculate in script load data
Load [FieldA] + [FieldB] as TOTAL
from table
size app will increase but performance is best


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. I know about pre-calculation in the script, which is not applicable in my case for some reasons.
Could you (or anybody else) confirm doubtless if the 2 calculations would lead to same result?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Both has given same results in my app.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if both fields comes from same table the result should be same for both calculations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Thomas,
If both columns have any numeric values then the result will be same. But if there is a possibility that any of the column can have NULL/Non numeric values then I will advise the first method for accuracy.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would try to expand on Chandan's comment. To avoid the null/non-numeric issue, you could also try a simpler way using RangeSum() like:
sum( {<[Date.Cal.Year]={2017}>} RangeSum([FieldA] , [FieldB]))


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
They will NOT give the same results if there are any null values.
For Sum(A+B), if A is null, then A+B is also null, so that value of B will not be in the sum result. But it will be in the sum result for Sum(A) + Sum(B). The same applies if B is null and A is not null.
Deciding which is the correct one depends on your requirements. But make the mistake of assuming that they are equivalent.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jonathan,
How it will work, when both facts are from different table ?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Treseco B,
In my case I very large data sets and have ensure performance.
Do you know how is your expression is executed?
sum( {<[Date.Cal.Year]={2017}>} RangeSum([FieldA] , [FieldB]))
Possible methods I see are:
a) Calculate the RangeSum for ALL (millions) of records and afterwards calculate the Sum with the Set Analysis
OR
b) The main calculation is the Sum considering the records in the Set Analysis only and then calculate the RangeSum for those records
If it´s method be I see this as a resolution also in case of large data sets.
What do you think?

- « Previous Replies
- Next Replies »