It looks like the clear() method is causing it. If we comment it out the formula is counted perfectly and the result is the same https://jsfiddle.net/zwvp8g4b/
You can load new data without using clear() the loadData(new_data) should work (and it works in the example) just perfectly.