+ Reply to Thread
Results 1 to 4 of 4

Several formulas in one cell + Logic fail

Hybrid View

varmgang Several formulas in one cell... 05-03-2009, 04:18 PM
DonkeyOte Re: Several formulas in one... 05-03-2009, 05:22 PM
varmgang Re: Several formulas in one... 05-03-2009, 06:40 PM
shg Re: Several formulas in one... 05-03-2009, 07:11 PM
  1. #1
    Registered User
    Join Date
    05-03-2009
    Location
    Norway
    MS-Off Ver
    Excel 2003
    Posts
    3

    Several formulas in one cell + Logic fail

    I have this troublesome formula I've been working on.

    According to what I've read so far in this forum, this will be cakewalk for you guys to find out of (or at least so I hope.. :-)
    I don't know much about Excel, and what I do know is just logic sense, and a bit of common math.

    My problem is in a sheet I use for my personal economy. (I'm a neatfreak, and a nerd...)

    The logic of my sheet is that I seperate the different type of monthly expenses, and sum them individually. The way I do this is that the A Column identyfies an expense (where 1 = rent, 2 = food, 3 = gas etc) while the C column is the expense itself, Example:

    A B C
    On account 500
    1 rent -200
    2 food -20
    3 gas -10
    2 food -10
    Sum expenses -240
    On account 260

    I then use this formula to discern them:
    {=ABS(SUM(IF(A$4:A$30=X;C$4:C$30;0)))}

    where X is substituted for the number in the A column.
    1 would give 200
    2 would give 30
    3 would give 10

    This works swimmingly. The problem comes here:

    A B C
    On account 500
    1 rent -200
    2 food -20
    3 gas -10
    2 food -10
    4 to saving -100
    Sum expenses -340
    On account 160

    As you see, what is going to my saving account is registered as an expence, which isn't right... (I want the sum expenses to still be 240) So I've tried to not have the "type 4" to be registered as an expense (but it still needs to be in there, to balance the account) So I made this formula for "Sum expenses":

    {=SUM(C4:C30)+(IF(A$4:A$30=4;ABS(C$4:C$34);0))}

    What this is supposed to do is to take the sum of the expenses, and add whatever is marked with 4 (that is -340+100=240). This doesn't work. I've tried changing it around a bit, and for some reason, the logical test in the IF part never gets "true", even though it "should" . If I simplify:

    {=SUM(C4:C30)+(IF(A$4:A$30=4;5;7))}

    The value of the cell will always end with a 7, never a 5, which it should if one of the A columns contained a 4.. (assuming, of course that the last digit of the original sum is 0, as in the examples...)

    I probably fail to see some logic Excel finds obvious..

    Any clue?

    PS: I can upload a clean copy of the sheet, if the problem isn't understandable.. I am however using a non-english Excel, do the formulas translate to other versions?
    Last edited by varmgang; 05-03-2009 at 06:45 PM. Reason: Solved!

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Several formulas in one cell + Logic fail

    RE: individual a/cs, no need to use an array here, ie:

    {=ABS(SUM(IF(A$4:A$30=X;C$4:C$30;0)))}

    can be replaced with a SUMIF

    =ABS(SUMIF(A4:A30;X;C4:C30))

    re: your savings...

    {=SUM(C4:C30)+(IF(A$4:A$30=4;ABS(C$4:C$34);0))}

    you need to discount the savings from the initial sum, eg:

    =ABS(SUMIF(A4:A30;"<>4";C4:C30))

    Does that help ?

  3. #3
    Registered User
    Join Date
    05-03-2009
    Location
    Norway
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Several formulas in one cell + Logic fail

    That works great! Thanks for the tip!

    Heh, I wish I knew about the SUMIF formula when I made the first formula.. Would have made things considerably easier..

    Followup question though:

    When I use the formula you suggested it works fine:
    =SUMIF(A4:A30;"<>4";C4:C30)

    but substituting 4 with a cell reference,

    =SUMIF(A4:A30;"<>A40";C4:C30)

    doesn't work. (A40=4 btw) (This is only me being nitpicky... It's simpler to change the reference cell once, than changing all the cells if I ever change anything)

    If anyone can tell me why my first suggestion for the formula didn't work, I would appreciate it! (Keeps me from doing the same errors again..)

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Several formulas in one cell + Logic fail

    but substituting 4 with a cell reference,

    =sumif(a4:a30;"<>a40";c4:c30)

    doesn't work.
    =sumif(a4:a30; "<>" & a40; c4:c30)
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1