The averaging blocks in the PLECS library do require periodicity and cannot be adapted to have a variable averaging time as an external input.
You could consider averaging over a longer period to approximate the losses, assuming a settled system. Of course, you’d need to find the right balance between the averaging time and the accuracy (because you’ll invariably capture a non-integer number of cycles), but perhaps you can determine “ballpark” losses this way.
For more accurate estimation of variable-frequency conduction losses you can probably process the loss waveform to use the edges as calculation triggers such that two successive rising edges mark the starting and ending of your averaging period.
If you want to fully engineer a solution for switching losses, I believe you would need to integrate the loss calculation into your controller design. The "Periodic Impulse Average" is a masked subsystem around a C-Script. One could add a "Period" input and replace the fixed-step task (for calculating the outputs and resetting the internal counters) with a discrete-variable task. However, unless you update the task hits for this discrete-variable task in the exact same way as the modulator, there is the risk that the switching cycle and the loss calculation will drift apart over time.
I hope this helps.