Sum Function

Stimulsoft Reports.NET discussion
ACordero
Posts: 25
Joined: Mon Sep 20, 2010 1:03 pm
Location: Valencia, CA

Sum Function

Post 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?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Sum Function

Post 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.
Attachments
600.SumDistinct.mrt
(22.97 KiB) Downloaded 587 times
ACordero
Posts: 25
Joined: Mon Sep 20, 2010 1:03 pm
Location: Valencia, CA

Sum Function

Post 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.
LukasT
Posts: 306
Joined: Mon May 03, 2010 2:50 am
Location: Czech Republic

Sum Function

Post 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...
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Sum Function

Post by Alex K. »

Hello,

Function SumDistinct() will be added in designer. Solution will be available in relise on end of september.

Thank you.
LukasT
Posts: 306
Joined: Mon May 03, 2010 2:50 am
Location: Czech Republic

Sum Function

Post by LukasT »

Aleksey, great news ;-) We are looking forward to the release.
Thank you very much!
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Sum Function

Post by Andrew »

We are always glad to help you!
ACordero
Posts: 25
Joined: Mon Sep 20, 2010 1:03 pm
Location: Valencia, CA

Sum Function

Post 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).
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Sum Function

Post by Alex K. »

Hello,

Please see the sample report in attachment.

Thank you.
Attachments
602.Sample Report.zip
(2.68 KiB) Downloaded 527 times
TheOmniAdam
Posts: 16
Joined: Mon Oct 11, 2010 9:43 am

Sum Function

Post 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?
Post Reply