I'd be glad to help you get P&L by Class your report customise to show prior year comparison in QuickBooks Online.
You can run the Profit and Loss by Class to achieve this. Once you successfully pull up the report, cutomise it to get the information you require. I will add a screenshot you can use as a reference along with the steps:
Go to Reports from the left menu.
Enter Profit and Loss by Class in the Search box and select it.
Select Customize and put a checkmark on the Class.
Choose the Compare another period dropdown and put a checkmark on Previous Period or Previous Year.
Click Run report.
Once done, you'll be able to see the prior year comparison on the report.