Combine Debit and Credit Amounts with an IF Formula in WPS Spreadsheets
Question details
Create one spreadsheet formula that returns the correct debit-to-credit or credit-to-debit difference according to the account type.

- Product
- WPS Spreadsheets
- Device & OS
- not provided
- Scenario
- The account code determines whether the calculation should subtract credit from debit or debit from credit.
- Observed behavior
- A simple logical test using only 1 or 0 may produce incorrect signs when the source account codes use different values or rule definitions.
Confirm which character in the account code identifies a debit account and which identifies a credit account. Also verify that the debit and credit values are in the expected columns before entering the formula.
Use an IF formula that reads the account-code character
Use this option when the second character of each account code consistently determines whether the row is debit or credit.
This formula checks the second character in A2, maps the relevant codes to a debit or credit result, and then subtracts the two amount columns in the correct order.
In WPS Spreadsheets, click the first cell where you want the calculated balance to appear, such as E2.
Type =IF(CHOOSE(MID(A2,2,1),1,0,0,0,1,1,1,1,1),C2-D2,D2-C2) and press Enter. This assumes the account code is in A2, debit is in C2, and credit is in D2.
Select the formula cell and drag the fill handle down, or double-click the fill handle, to apply the calculation to the remaining rows.

Look up debit and credit rules from an account table
Use this option when account classifications are maintained in a separate table rather than determined by one fixed character position.
Calculate only the unsigned difference between debit and credit
Use this option when you only need the size of the difference and do not need a debit or credit sign.
Build Debit and Credit Logic with WPS Spreadsheets Formulas
WPS Spreadsheets lets you enter IF, MID, CHOOSE, ABS, and lookup formulas to calculate debit and credit differences according to account-code rules. Use familiar worksheet tools to test formulas, fill results down, and manage account rule tables efficiently.
- 1. Open the accounting worksheet: Launch WPS Spreadsheets and open the workbook containing your account code, debit, and credit columns.
- 2. Choose the first balance cell: Click the first empty cell in the balance or result column, such as E2.
- 3. Enter the appropriate formula: Use the formula bar to enter an IF formula for account-code rules, a lookup formula for a rules table, or =ABS(D2-C2) for an unsigned difference.
- 4. Confirm and fill down: Press Enter to calculate the first result, then drag or double-click the fill handle to apply the formula to all transaction rows.

Frequently Asked Questions
How do I calculate debit minus credit for debit accounts and credit minus debit for credit accounts?
Use an IF formula that tests the account classification, such as =IF(logical_test,C2-D2,D2-C2). Replace logical_test with a test based on your account code or a lookup result.
Why does an IF formula based on 1 and 0 return the wrong debit-credit sign?
The source data may use account codes other than the assumed 1 and 0 values. Check the actual account-code rule, such as a specific character returned by MID(A2,2,1), and revise the logical mapping.
What does =ABS(D2-C2) do in a debit and credit worksheet?
It returns the absolute difference between D2 and C2. The result is always positive or zero, so it does not indicate whether the balance is debit or credit.
When should I use an account lookup table instead of a nested formula?
Use a lookup table when account classifications are numerous, can change, or are not consistently represented by a character in the account code. Store each code and its TRUE or FALSE debit status in a separate table.
Can WPS Spreadsheets open Excel files containing debit and credit formulas?
Yes. WPS Spreadsheets can open and edit Microsoft Excel .xlsx and .xls files. Review calculated results after opening the workbook, especially if it uses newer or complex lookup functions.




