Yes, something like this it works as expected.
It does not factor in electricity usage. The cost is calculated by the dollar value you assign to a spool in the filament settings. Here is a good post by @lkraus about where to find this value.