How trading fees are calculated during partial fills?

I noticed that when my order gets filled in multiple parts instead of all at once, the final trading fee sometimes ends up being different than I expected.

Are fees calculated separately for each partial fill based on the execution price and liquidity at that moment, or is there a combined calculation after the order is fully completed? Also, do maker/taker rates change depending on how each portion of the order is matched?

An example breakdown would really help.