0

In my problem, I have data about customers and seller:

customer, seller, amount
cus1, sel1, 78
cus2, sel1, 34
cus3, sel2, 25
cus2, sel1, 13
cus2, sel1, 11
cus3, sel2, 18
cus4, sel3, 50

...I would like to know how many customers each seller have. Thus I would like to construct a row chart showing the top 10 sellers with the biggest amount of clients.

I tried:

this.sellerDim = this.ndx.dimension(function(d: any) {return d.seller;});
this.customerDim = this.ndx.dimension(function(d: any) {return d.customer;});

this.sellerCount = this.sellerDim.group();

I also tried something like:

this.sellerCount = this.sellerDim.group().reduceSum(function(d:any){return d.customerDim});

...but it did not work out.

for displaying the chart I am using:

this.topSellerChart = dc.rowChart("#chart-row");

this.topSellerChart.data(function(d: any){
                                return d.order(function (d: any) {
                                    return d;
                                }).top(10);
                             })
                      .dimension(this.sellerDim)
                      .group(this.sellerCount)
                      .elasticX(true)
                      .controlsUseVisibility(true);

anyhow I and convinced that the mistake is during the .group() creation.

So, does anyone know how can I group sellers without counting more then once the same customer?

Roger A. Leite
  • 394
  • 2
  • 18
  • Possible duplicate of [crossfilter "double grouping" where key is the value of another reduction](https://stackoverflow.com/questions/42109965/crossfilter-double-grouping-where-key-is-the-value-of-another-reduction) – Gordon May 30 '17 at 13:51
  • This is often called a "double grouping" - it's not something crossfilter directly supports but it can be done. I've linked one previous question but lmk if it doesn't apply and I'll take another look. – Gordon May 30 '17 at 13:52
  • Isn't it more like what I usually call exception aggregation? You want the number of unique customers for each seller, right? I think this answer may help you: https://stackoverflow.com/questions/42391290/avoid-multiple-sums-in-custom-crossfilter-reduce-functions/42400837#42400837 – Ethan Jewett May 31 '17 at 18:42

0 Answers0