i made a quick flow for you with a formula.
just change the timestamp with th mqtt input.
[{"id":"27ee89f8.d3a6c6","type":"inject","z":"77705272.2fb44c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":180,"wires":[["3e97606.cf3b1a"]]},{"id":"250c6f55.d881","type":"inject","z":"77705272.2fb44c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":320,"wires":[["bb39ee40.1897d"]]},{"id":"3e97606.cf3b1a","type":"change","z":"77705272.2fb44c","name":"","rules":[{"t":"set","p":"income","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":180,"wires":[["714e8906.920db8","1cf69bf8.a51954"]]},{"id":"bb39ee40.1897d","type":"change","z":"77705272.2fb44c","name":"","rules":[{"t":"set","p":"outgoing","pt":"flow","to":".payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":320,"wires":[["7970dd98.a965f4","fa8138e8.1da4f8"]]},{"id":"2d60b2fd.5aec4e","type":"function","z":"77705272.2fb44c","name":"function","func":"var income = flow.get('income');\nvar outgoing = flow.get('outgoing');\nmsg.payload = income - outgoing;//or what ever kind of formula you want\n\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":600,"wires":[["c5ec5317.afe59"]]},{"id":"7970dd98.a965f4","type":"debug","z":"77705272.2fb44c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":320,"wires":},{"id":"714e8906.920db8","type":"debug","z":"77705272.2fb44c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":180,"wires":},{"id":"1cf69bf8.a51954","type":"link out","z":"77705272.2fb44c","name":"in","links":["6cf07c18.be9104"],"x":975,"y":120,"wires":},{"id":"fa8138e8.1da4f8","type":"link out","z":"77705272.2fb44c","name":"out","links":["274642cd.16094e"],"x":975,"y":380,"wires":},{"id":"6cf07c18.be9104","type":"link in","z":"77705272.2fb44c","name":"","links":["1cf69bf8.a51954"],"x":315,"y":540,"wires":[["2d60b2fd.5aec4e"]]},{"id":"274642cd.16094e","type":"link in","z":"77705272.2fb44c","name":"","links":["fa8138e8.1da4f8"],"x":315,"y":660,"wires":[["2d60b2fd.5aec4e"]]},{"id":"c5ec5317.afe59","type":"debug","z":"77705272.2fb44c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1210,"y":600,"wires":}]