title: Javascript multi group data like sql group by and sum
body: <p>I've been going around and around on this problem to produce 2 arrays for a <a href="http://www.chartjs.org/docs/#getting-started-creating-a-chart" rel="nofollow noreferrer">chart.js data source</a>.</p>
  
  <pre><code>let data = [
      { date: '7/6/2016', tenant: 'BiggeCo', template: 'Meeting Room', count: 100 },
      { date: '7/6/2016', tenant: 'BiggeCo', template: 'All Hands MR', count: 200 },
      { date: '7/6/2016', tenant: 'SmallCo', template: 'Meeting Room', count: 10 },
      { date: '7/6/2016', tenant: 'SmallCo', template: 'All Hands MR', count: 110 },
      { date: '8/6/2016', tenant: 'BiggeCo', template: 'Meeting Room', count: 120 },
      { date: '8/6/2016', tenant: 'BiggeCo', template: 'All Hands MR', count: 30 },
      { date: '8/6/2016', tenant: 'SmallCo', template: 'Meeting Room', count: 60 },
      { date: '8/6/2016', tenant: 'SmallCo', template: 'All Hands MR', count: 70 }
  ];
  </code></pre>
  
  <p>Given this input data and told to group by a variable number of columns, e.g. in my examples name and tenant, but could just be on 1, say date, produce label keys and then a sum of count for the dataset data of the graph.</p>
  
  <p>Target Labels output:</p>
  
  <pre><code>let targetLabels = [
      ['7/6/2016', 'BiggeCo'],
      ['7/6/2016', 'SmallCo'],
      ['8/6/2016', 'BiggeCo'],
      ['8/6/2016', 'SmallCo']
  ];
  </code></pre>
  
  <p>Target DataSets output:</p>
  
  <pre><code>let targetDataSets = [
      {
          label: 'Count',
          data: [300, 120, 150, 130]
      }
  ];
  </code></pre>
  
  <p>So far I've got the follow but it seems clunky and I'm not sure how to then get the sum of the count column and allow variable numbers of columns easily.</p>
  
  <pre><code>let temp = _.transform(data, function(result, value, key) {
      if (!_.some(result, function (r) { return r[0] == value['date'] &amp;&amp; r[1] == value['tenant']; })) {
          result.push([ value['date'], value['tenant'] ]);
      }
  }, []);
  </code></pre>
  
  <p>In SQL I'd just write</p>
  
  <pre><code>SELECT name, tenant, sum(count) FROM table GROUP BY name, tenant
  </code></pre>
  
  <p>Can anyone offer any guidance?</p>
  
  <p>This looks close to what I want to do but I want to do it over multiple properties</p>
  
  <p><a href="https://stackoverflow.com/questions/24130110/how-can-i-reduce-array-with-non-unique-elements-by-summing-their-second-value-wi">How can I reduce array with non-unique elements by summing their second value with lodash/underscore?</a></p>