This is a migrated thread and some comments may be shown as answers.

CountDistinct in Group-by Expression

3 Answers 225 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wallace
Top achievements
Rank 1
Wallace asked on 13 Apr 2010, 02:23 PM
I'm having a problem using the CountDisinct aggregate in a group by expression in the RadGrid. I'm using the aggregate function to get a unique count total in my Group header. I can reproduce this issue in the online demo as follows:

If i take the default grouping expression  'Country [My Country], count(Country) Items [My Items], Sum(TotalAmount) GroupTotal [Group Total ] Group By Country'
and i change 'count(Country)' to 'CountDistinct(Country)' suddenly the total for My Items becomes blank. The final grouping expression looks like this Country [My Country], CountDistinct(Country) Items [My Items], Sum(TotalAmount) GroupTotal [Group Total ] Group By Country.
What am i doing wrong? Is there another way to get a count of unique items in the group header?

Thanks
Marcel



3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 16 Apr 2010, 08:03 AM
Hi Wallace,

I noticed that you have opened a duplicate post on the same matter. Please, refer to the other support ticket post for additional information. To avoid duplicate posts, I suggest you continue the communication there.

Regards,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
SMA SOFTWARE
Top achievements
Rank 1
answered on 29 Apr 2010, 08:17 PM
There Where?

I am having the same problem, can you post a link to the thread?

tks
0
Wallace
Top achievements
Rank 1
answered on 30 Apr 2010, 09:19 AM
I logged a support ticket - this is their response:

"Thank you for contacting us.

Currently the RadGrid does not supports using the CountDisinct aggregate in a group by expression. Also I have alerted our dev team about this issue.

If you need further assistance, do not hesitate to contact us again.

Greetings,
Radoslav
the Telerik team
"


I did manage to create a work around as follows:
After fetching the dataset in code (ds) i create a new column called "UniqueCallCount". Then i loop thru each row in the datatable and check the Call_Id field. If a new Call_Id is encountered i make the UniqueCallCount column = 1, if the Call_Id has already been encountered Ie. a duplicate then i make the UniqueCallCount = 0.
So instead of the following group by expression CountDistinct(Call_Id) [Calls] Group by SomeOtherField i have changed it to SUM(UniqueCallCount) [Calls] Group by SomeOtherField

Here is a code snippet:


 

Dim colUniqueCallCount As New DataColumn("UniqueCallCount", New Integer().GetType())

 

ds.Tables(

"Open_Calls").Columns.Add(colUniqueCallCount)

 

 

Dim callIDs As New List(Of Integer)

 

 

For Each row As DataRow In ds.Tables("Open_Calls").Rows

 

 

    If Not callIDs.Contains(row("Call_Id")) Or allowDuplicates Then

 

        row(

"UniqueCallCount") = 1

 

        callIDs.Add(row(

"Call_Id"))

 

 

    End If

 

 

Next


Hope this helps :-)
Marcel

 

Tags
Grid
Asked by
Wallace
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
SMA SOFTWARE
Top achievements
Rank 1
Wallace
Top achievements
Rank 1
Share this question
or