I'm going to assume your data source is ordered by invoice and line number already. If it isn't then you first need to load to load the unsorted data and then use a resident load to order the data.
You can use the Previous and Peek functions. Something like:
IF(INVOICE = Previous(INVOICE) AND DOC_TYPE <> 'KA', peek('DEB_CRED2'), DEB_CRED) as DEB_CRED2