You have three accounts 30003, 30004 and 30005. The balances are as follows:
D C
30003 34 50
30004 34 34
30005 87 21
For 30003 credit is higher than debit. 30004 hold zero balance as both debit and credit are equals. 30005 holds debit balance as debit is higher than credit.
How could we do a report which shows the balances clearly ?
For example, 30003 D is 0 and C 16, 30004 is zero, 30005 D 66 and C 0.
The IF-sentence should be if D is higher than C, then D is D-C and C is zero. If C higher than D, then C is C-D and D is zero.

The sentence in D3 is =IF(B3>C3;B3-C3;0) and E3 is =IF(C3>B3;C3-B3;0).
Another option to visualize account balances is to define whether balance is debit or credit and what is the balance.
The balance for 30003 is C 16, 30004 is DC 0, and 30005 is D 66.
We avoid some unnecessary zeroes.
The debit or credit is defined with dual IF-sentence. First if is checking if C and D have equal balance, then indication is DC. If this is not the case, but D is higher than C, then the returned value is D, otherwise the value is C.

The sentence in D3 is checking if D equals to C, if so, then the returned value is DC. If D is higher than C, then the value is D, if not, then the value will be C.
E3 is checking if D is higher than C. Luckily, the sentence works also for cases when D is as high as C, returning zero.
Maybe showing summarized balance is more informative than showing both debit and credit balances. All the examples in this blog were done with IF-function.