data visualization to the end user reduceaddavg(takes the same and arguments but now you actually use vyou don' need your data to set the initial values of in this casealthough you can if you want to your stock is summed up for every record you addand then the average is calculated based on the accumulated sum and record countvar reduceremoveavg function( , ) count - stocksum stocksum number( stock) stockavg math round( stocksum count)return pthe reduceremoveavg(function looks similar but does the oppositewhen record is removedthe count and sum are lowered the average always calculates the same wayso there' no need to change that formula the moment of truthyou apply this homebrewed mapreduce function to the data setdatafiltered mednamedim group(reduce(reduceaddavgreduceremoveavg,reduceinitavgbusiness as usualdraw result table variablesintable ["key","value stockavg"filteredtable empty(append(createtable(datafiltered top(infinity)variablesintable,'reduced table'))reduce(takes the functions (reduceinitavg()reduceaddavg()and reduceremoveavg()as input arguments notice how the name of your output variable has changed from value to value stockavg because you defined the reduce functions yourselfyou can output many variables if you want to thereforevalue has changed into an object containing all the variables you calculatedstocksum and count are also in there the results speak for themselvesas shown in figure it seems we've borrowed cimalgex from other hospitalsgoing into an average negative stock this is all the crossfilter you need to know to work with dc jsso let' move on and bring out those interactive graphs figure mapreduced table with average stock per medicine