Aggregate datatable with percentage for grouped elements dc.js


How to display failure % in the data table? I have the following csv and I am calculating the percentage of failures for each "name" field , I want to display the total failure percentage for each "name" in datatable

Customer | year| Week |Failure_Reason| name | Type | Count ___________________________________________________________________________ A 2018 29 Delay hours Express Air PASSENGER 27 ___________________________________________________________________________ A 2018 26 Maintenance missed Express Air PASSENGER 58 ___________________________________________________________________________ A 2018 26 Delay hours Domestic 5 ___________________________________________________________________________ A 2018 27 N Domestic HIGH SPEED 29 ___________________________________________________________________________ A 2018 30 Maintenance missed International PASSENGER 11 ___________________________________________________________________________ A 2018 32 N Domestic PASSENGER 53

Code for the dimesion and group:

var ndx= crossfilter(data); var all= ndx.groupAll(); var CTypedim=ndx.dimension(function(d) {return d["name"]+ ',' + d["Customer"];}) var CTypeGroup=CTypedim.group(); var percentFailures = CTypedim.group().reduce( function(p, v) { p.counter+= Number(v.count); p.failures += Number(v.Failure_Reason != 'N' ? v.count : 0); p.failPercent = p.counter ? p.failures/p.counter : 0; return p; }, function(p, v) { p.counter-= Number(v.count); p.failures -= Number(v.Failure_Reason != 'N' ? v.count : 0); p.failPercent = p.counter ? p.failures/p.counter : 0; return p; }, function() { return { counter: 0, failures: 0, failPercent: 0 }; }); dataTable.width(800).height(800) .dimension(percentFailures) .group(function(d) { return "" }) .size(100) .columns([ function(d) { return d.Customer; }, function(d) { return d.year; }, function(d) { return d.value.failpercent*100; }, function(d) { return d.name; }, ]) .sortBy(function(d){ return d.year; }) .order(d3.descending);

Need to display aggregated datavtable as follows:

Customer | Year| Failure%| name | _____________________________________________ A 2018 100% Express Air _____________________________________________ A 2018 5.7% Domestic _____________________________________________ A 2018 100% International _____________________________________________

<a href="https://i.stack.imgur.com/rXQI2.jpg" rel="nofollow"><img alt="Result" class="b-lazy" data-src="https://i.stack.imgur.com/rXQI2.jpg" data-original="https://i.stack.imgur.com/rXQI2.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>


You're on the right track, keep going!

You'll need to use the aggregated fields in your table:

.columns([ function(d) { return d.key.split(',')[1]; }, // customer part of multikey function(d) { return d.year; }, function(d) { return d.value.failPercent*100; }, // capitalize consistently function(d) { return d.key.split(',')[0]; }, // name part of multikey ])

Using the year is problematic! Because once you aggregate, you don't really know what year each aggregated value represents - and it may represent multiple years. If you can drop that column, I recommend it.


  • Change region format to another language with VBA
  • SAS - What is the SQL language used in a PROC SQL?
  • Regex for alphanumeric and the + character
  • New rails installation with error when entering url
  • Why do Rhino Stubs allow me to set expectations on them?
  • How to make multi-line UILabel text fit within predefined width without wrapping mid-word
  • Facebook debug returns 403 Forbidden
  • Do not require authentication for OPTIONS requests
  • Working with hyphenated words in SOLR
  • Using the Menu, Back, Home buttons with AIR for Android, Flash CS6
  • Python: analyze a list comprehension with dis
  • URL detection adobe air desktop widget
  • Search for unicode text inside Windows XP
  • How to pass multiple records to update with one sql statement in Dapper
  • Regexp to literally interpret \\t as \\t and not tab
  • How to make GAE+ django pick up my .po and .mo translations
  • html entities not converting special characters
  • In Rails, what could cause a user to have another user's session?
  • How do I increase font size in RStudio Help pane?
  • Does anyone have recommendations for a good (and lightweight!) PHP mailer library?
  • QStandardItemModel::removeRows() does not work in my use case
  • Making an email label a hyperlink
  • Is it good to have multiple database running in a same project?
  • How to display international scripts in QLabels?
  • Store a sequence of specific class types in Scala?
  • Add the % on tab when working with HAML on vim
  • Why does the first run of “XCTestCase -measureBlock:” takes so much time?
  • PyYaml parses '9:00' as int
  • Unity 5.1 Animator Controller not transitioning
  • While loop won't end when I tell it in JavaScript
  • Get rendered html code in Backing Component from Composite Component
  • How to get file download speed (transfer rate) with php?
  • Implementation of RTTI using typeid
  • Watson Conversation - Why is the ANYTHING ELSE node not chosen
  • Local Development, Apache vs Developer - file permissions
  • Marklogic : Query response time is very high
  • Menu Color Fade on Hover with Jquery
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal