Page 1 of 2
Sum Function
Posted: Mon Sep 20, 2010 4:28 pm
by ACordero
I have a dataset like this:
Claim # - Contact - Claim Total Paid
1 -- Joe -- $1500
1 -- Jerry -- $1500
1 -- Harry -- $1500
1 -- Nancy -- $1500
TOTAL $6000
So the Claim Total Paid is repeated for each of the Contacts. That means when we try to total the Paid column, it shows 4x the actual total. We just need the one amount to total for each claim number, in this case it should be $1500. Any ideas on how to resolve this?
Sum Function
Posted: Tue Sep 21, 2010 2:20 am
by Alex K.
Hello,
If we understand you correctly you want to count the distinct values. Standard feature in the designer there, but you can implement it yourself using the following code:
Code: Select all
private Hashtable hTable = new Hashtable();
private int sumDistinct = 0;
private int indexKey = 0;
public int SumDistinct(int addValue)
{
if (!hTable.ContainsValue(addValue))
{
sumDistinct = sumDistinct + addValue;
hTable.Add(indexKey, addValue);
indexKey ++;
}
return addValue;
}
Please see the sample report in attachment.
Thank you.
Sum Function
Posted: Tue Sep 21, 2010 3:17 pm
by ACordero
Aleksey wrote:Hello,
If we understand you correctly you want to count the distinct values. Standard feature in the designer there, but you can implement it yourself using the following code:
Code: Select all
private Hashtable hTable = new Hashtable();
private int sumDistinct = 0;
private int indexKey = 0;
public int SumDistinct(int addValue)
{
if (!hTable.ContainsValue(addValue))
{
sumDistinct = sumDistinct + addValue;
hTable.Add(indexKey, addValue);
indexKey ++;
}
return addValue;
}
Please see the sample report in attachment.
Thank you.
The issue is actually a little more complex. Expanding on my example:
Claim # Contact Claim Total Paid
1 Joe $1500
1 Jerry $1500
1 Harry $1500
1 Nancy $1500
CLAIM TOTAL $1500 (Subtotal 1)
2 John $2000
2 Hank $2000
CLAIM TOTAL $2000 (Subtotal 2)
3 Jimmy $1500
CLAIM TOTAL $1500 (Subtotal 3)
GRAND TOTAL $5000 (Sum of Subtotal 1, 2 & 3)
I can make each Claim (1, 2 & 3) total correctly, but what I can’t do is calculate the GRAND TOTAL amount. A ‘sum distinct’ function won’t work because 2 Claims may have the same Total Paid amount.
Sum Function
Posted: Wed Sep 22, 2010 1:36 am
by LukasT
Hello,
that is my talk... I thing, that SumDistinct is usable in more complex cases than this workaround makes possible... I thing, better will be to implement this function into base Stimulsoft functions... This example didn't help even me ...
Thank you...
Sum Function
Posted: Wed Sep 22, 2010 2:28 am
by Alex K.
Hello,
Function SumDistinct() will be added in designer. Solution will be available in relise on end of september.
Thank you.
Sum Function
Posted: Wed Sep 22, 2010 5:29 am
by LukasT
Aleksey, great news

We are looking forward to the release.
Thank you very much!
Sum Function
Posted: Wed Sep 22, 2010 6:31 am
by Andrew
We are always glad to help you!
Sum Function
Posted: Wed Sep 22, 2010 9:44 am
by ACordero
I don’t believe ‘Sum Distinct’ will work for our problem. We don’t want to count ‘distinct’ values (see example, where Subtotal 1 & SubTotal 3 are identical, but must be added separately).
We need to be able to total the Subtotals (1, 2 & 3).
Sum Function
Posted: Thu Sep 23, 2010 4:04 am
by Alex K.
Hello,
Please see the sample report in attachment.
Thank you.
Sum Function
Posted: Wed Oct 13, 2010 11:45 am
by TheOmniAdam
I have a very similar problem with a report. I can't get your sample report to work because the dataset seems to be incorrect or not lined up, but I don't understand where SumDistinct comes from or if it does what I want it to do. The same with GrandTotal. How can I get this report to work to see if it's doing what I need it to do- and where does SumDistinct get called from- and how do I call it on the right data?