Unplanned
Last Updated: 21 Oct 2021 06:39 by ADMIN
Dave
Created on: 20 Oct 2021 12:35
Category: UI for WinForms
Type: Feature Request
0
RadPivotGrid: Add new DistinctCountAggregateFunction
This aggregate function should count all the distinct values.
4 comments
ADMIN
Hristo
Posted on: 21 Oct 2021 06:39

Hello Dave,

You can check your Ticket ID: 1539825 where I sent you the project in VB.NET. I am also attaching it here for reference.

I hope that it will work for your project.

Regards,
Hristo
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Dave
Posted on: 20 Oct 2021 17:43

per below.. I can't seem to convert this to vb.net properly.

 

this.provider.AggregateDescriptions.Add(new PropertyAggregateDescription()
{
    PropertyName = "Product",
    AggregateFunction = new DistinctCountAggregateFunction()
});

 

 

Dave
Posted on: 20 Oct 2021 16:47

Thank you Hristo, would you happen to have a vb.net version of this?

 

ADMIN
Hristo
Posted on: 20 Oct 2021 13:10

Hello,

This is a sample implementation of a the DistinctCountAggregate: 

public sealed class DistinctCountAggregateFunction : AggregateFunction
    {
        public override string DisplayName
        {
            get
            {
                return "Distinct Count";
            }
        }

        protected override AggregateValue CreateAggregate(IAggregateContext context)
        {
            return new DistinctCountAggregate();
        }

        public override string GetStringFormat(Type dataType, string format)
        {
            return "G";
        }

        public override int GetHashCode()
        {
            return 1;
        }

        public override bool Equals(object obj)
        {
            return obj is DistinctCountAggregateFunction;
        }

        public override string ToString()
        {
            return "Distinct Count";
        }

        protected override Cloneable CreateInstanceCore()
        {
            return new DistinctCountAggregateFunction();
        }

        protected override void CloneCore(Cloneable source)
        {
        }
    }

public class DistinctCountAggregate : AggregateValue, IConvertibleAggregateValue<double>
    {
        private HashSet<object> aggregateValues = new HashSet<object>();

        protected override object GetValueOverride()
        {
            return this.aggregateValues.Count;
        }

        protected override void AccumulateOverride(object item)
        {
            this.aggregateValues.Add(item);
        }

        protected override void MergeOverride(AggregateValue childAggregate)
        {
            DistinctCountAggregate distinctCountAggregate = childAggregate as DistinctCountAggregate;
            if (distinctCountAggregate == null)
            {
                return;
            }

            foreach (var aggregateValue in distinctCountAggregate.aggregateValues)
            {
                this.aggregateValues.Add(aggregateValue);
            }
        }

        bool IConvertibleAggregateValue<double>.TryConvertValue(out double value)
        {
            value = Convert.ToDouble(this.GetValueOverride());
            
            return true;
        }
    }

Later it can be added to the pivot like this:

this.provider.AggregateDescriptions.Add(new PropertyAggregateDescription()
{
    PropertyName = "Product",
    AggregateFunction = new DistinctCountAggregateFunction()
});

Regards,
Hristo
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.