Forum Discussion
If formula not working when I try to combine the 2 formulas in Excel
- Feb 01, 2024
Sharon21 "Is a debit always = 1 and credit always = 0 in excel?" No. This is how I setup the formulas to determine which accounts have a "normal" debit balance, and which ones have a "normal" credit balance. I used 1's and 0's as the return values for the CHOOSE function because it's shorter/simpler than using TRUE's and FALSE's (the IF function will interpret 1 as TRUE and 0 as FALSE). The main goal is to use a formula that will return TRUE or FALSE, to be passed to the logical_test parameter of the IF function.
The generic syntax for the IF function is:
=IF(logical_test, [value_if_true], [value_if_false])In the examples I've used thus far, the [value_if_true] is Debit-Credit and the [value_if_false] is Credit-Debit. As such, we need to use a formula for the logical_test that will return TRUE (or 1) for an account with a "normal" debit balance (Asset or Expense accounts), and FALSE (or 0) for an account with a "normal" credit balance (Liability, Equity or Revenue accounts). This is where the CHOOSE function comes in.
The generic syntax for the CHOOSE function is:
=CHOOSE(index_num, value1, [value2], ...)The index_num determines which value is returned. You can specify up to 254 values to choose from. For example, if the index_num is 4, the 4th value is returned:
Since your account codes appeared to follow a pattern, where the first number after the "O" indicates the account type/class (O4 = Sales; O6 = Cost; O7 = Expense), I made the assumption, based on my own accounting experience working with Sage 50, that all accounts beginning with O1 = Assets, O2 = Liabilities, O3 = Equity, O4 = Revenue and O5 thru O9 = Expenses. As such, I used the MID function to extract the 2nd character to be passed to the index_num parameter.
For example, if the account code "O4020216" is used in cell A2, the formula will evaluate as follows:
=IF(CHOOSE(MID(A2, 2, 1), 1, 0, 0, 0, 1, 1, 1, 1, 1), C2-D2, D2-C2) =IF(CHOOSE(MID("O4020216", 2, 1), 1, 0, 0, 0, 1, 1, 1, 1, 1), C2-D2, D2-C2) =IF(CHOOSE("4", 1, 0, 0, 0, 1, 1, 1, 1, 1), C2-D2, D2-C2) =IF(0, C2-D2, D2-C2) =IF(FALSE, C2-D2, D2-C2) =D2-C2 =150-0 =150Having said that, if I was wrong in assuming that ALL of your account codes follow a strict numbering pattern, the XLOOKUP method that I demonstrated in the sample workbook attached to my previous reply can be used (please download and open that file to see how it works).
The same basic IF formula is used, but instead of using CHOOSE/MID as the logical_test, use XLOOKUP to return the matching value from a separate lookup table. For example...
=IF(XLOOKUP(A2, tblAccounts[Code], tblAccounts[IsDebit], TRUE), C2-D2, D2-C2)...where the lookup table was formatted as a structured Excel table named tblAccounts.
If further information is required, please see:
Wow -That is simple and seems to work. I will try it on my real spreadsheet and let you know. Thank you!!!
- Sharon21Jan 30, 2024Copper ContributorHarun24HR
Since the example deals with debits and credits, some of the results might be a negative number and not the absolute value number. Would I use an if statement to make that happen? For example:
619 Cost Tape 18.00 20.00 -2 2
Column E should be the real answer and column F is the absolute value, and not the correct answer? What would that function look like?
Thank you.- djclementsJan 30, 2024Silver Contributor
Sharon21 You would first need a way to identify the account type (Asset and Expense = normal Debit balance; Liability, Equity and Revenue = normal Credit balance). Does your chart of accounts follow a strict numbering system for the account codes (shown in column A)? It looks like 200 accounts are Assets, 400's are Revenue, and possibly all 500's and above are Expenses... does that mean 100's are liabilities and 300's are Equity?
Just as an example, if my assumptions are correct, you could try the following formula:
=IF(OR(INT(A1/100)=2, A1>=500), C1-D1, D1-C1)The logical test uses the OR function to determine if the account code in cell A1 begins with a 2 (Asset) or is greater than or equal to 500 (Expense). If the result is true, the formula returns Debit - Credit; if not, it returns Credit - Debit.
I hope that makes sense. Cheers!
- Sharon21Jan 30, 2024Copper Contributor
- Harun24HRJan 30, 2024Bronze ContributorGlad to know! If it helps then please mark this answer as best response to treat the question as solved.