Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom calculated aggregated field in Crossfilter
    primarykey
    data
    text
    <p>I have been playing with <strong>crossfilter</strong> and found it great but hit into a wall recently. I don't know if my problem needs <strong>crossfilter</strong> at all, so happy to hear any alternatives solutions.</p> <p>My data looks like this:</p> <pre><code>[{ year: "1987", country: "UK", product: "pineapple", tons_available: 10, tons_sold: 8 }, { year: "1987", country: "US", product: "pineapple", tons_available: 34, tons_sold: 18}, { year: "1987", country: "UK", product: "pear", tons_available: 4, tons_sold: 3}, { year: "1987", country: "US", product: "pear", tons_available: 23, tons_sold: 20}, { year: "1988", country: "UK", product: "pineapple", tons_available: 12, tons_sold: 3}, { year: "1988", country: "US", product: "pineapple", tons_available: 56, tons_sold: 6}, { year: "1988", country: "UK", product: "pear", tons_available: 32, tons_sold: 32}, { year: "1988", country: "US", product: "pear", tons_available: 31, tons_sold: 8}, and on, and on...] </code></pre> <p>I want to aggregate yearly data and was able to do it for metrics already available like "tons_available" and "tons_sold".</p> <pre><code>var by_week = data_to_filter.dimension( function(d) { return d.year; }); var tons_sold_by_week = by_week.group() .reduceSum(function(d) { return d.tons_sold; }); </code></pre> <p>However, I cannot find a way to create metrics on top of the aggregated object. For example, I would like to create a <em>sell-through-rate per year</em>. For this, I would need to sum all the field per year and then only divide: tons_sold/tons_available.</p> <p>This ideally would give me a json formatted as:</p> <pre><code>[{ year: "1987", tons_available: 71, tons_sold: 49 str: 0.69 }, { year: "1988", tons_available: 131, tons_sold: 49, str: 0.37 }, and on, and on...] </code></pre> <p>It seems to me that the aggregated object only keep the summed variables and result with just one couple key/value per year. </p> <p>Is there way to achieve what I am after?</p> <p>Thanks a lot!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload