Search to get sales order details or invoice details according to the record type. If type is sales order then fetch only details of applying transaction as invoices.
Type: Formula(text) : CASE WHEN ({type})= ‘Sales Order’ AND ({applyingtransaction.type})= ‘Invoice’ THEN 1 WHEN({type})= ‘Invoice’ THEN 1 ELSE 0 END