I’m not sure if I understand your question right. You ask “Is there any better way to deal with checks in case the source table contains to GR or no Invoice?” but what does deal mean? Do you want to exclude such cases from the ratio entirely (i.e. it calculated as if they didn’t exist) or do you want them to be given the value 0 so they are included as a case not fulfilling the condition?
I’m also not sure why you’re including the case “EKBE”.”SHKZG” = ‘H’ in the second example but not the first. If you are trying to catch the cases where “EKBE”.”SHKZG” is left empty you could use the following condition: ISNULL(“EKBE”.”SHKZG”) = 1. You can also use ISNULL to catch the cases for which RSEG is empty.
I think using case when statements is the way to go in this case. If it’s important that the code is easy for others to quickly understand then it could really help to write more expressive comments explaining what each section does in plain English. I.e. under “Order Quantity = GR Quantity” you could write “Check if the amount actually ordered lies within the tolerance of the planned order (and was bought on debit)”.
If you have further questions, please feel free to write back to us with further details clarifying what you aim to achieve and we will try to help you further.