+ Reply to Thread
Results 1 to 9 of 9

Conditional weighted average

  1. #1
    Registered User
    Join Date
    04-20-2009
    Location
    Internet
    MS-Off Ver
    Excel 2007
    Posts
    7

    Conditional weighted average

    I have two columns. One has cost (column A) and the other has profit (column B). I'd like to calculate the percentage profit as a function of how much something cost. So, if it cost $100 and the profit was $20 I would like to calculate 20%. For all percentages, I'd like to average them. I understand this is a "weighted average" and was able to get this working with this formula:

    Please Login or Register  to view this content.
    However, I don't want to include entries where the profit column has a negative value. I tried something like this:

    Please Login or Register  to view this content.
    This doesn't seem to work quite right as it's not ignoring the cost entry when the profit entry is negative. Any advice?
    Last edited by saturnexcel; 04-20-2009 at 04:19 PM.

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

    Re: Conditional weighted average

    Welcome to the forum.

    Maybe =SUMIF(B1:B20, ">0") / SUMIF(B1:B20, ">0", A1:A20)

    You might want to be sure you understand what question this formula answers.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    04-20-2009
    Location
    Internet
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Conditional weighted average

    Quote Originally Posted by shg View Post
    Welcome to the forum.

    Maybe =SUMIF(B1:B20, ">0") / SUMIF(B1:B20, ">0", A1:A20)

    You might want to be sure you understand what question this formula answers.
    Thanks for the welcome. I want a weighted profit percentage. Basically, I'd like to know how much profit I'm making based on the cost of a unit.

    Your formula isn't averaging the percentages, but rather an overall average. Thus, it's not a weighted average.

    I got a little closer with this:

    Please Login or Register  to view this content.
    It works if I specify a range (e.g. - I use B1:B20 and so forth). Doesn't work as typed though.

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

    Re: Conditional weighted average

    Array formula: =AVERAGE(IF(B1:B20>0, B1:B20 / A1:A20))

  5. #5
    Registered User
    Join Date
    04-20-2009
    Location
    Internet
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Conditional weighted average

    Quote Originally Posted by shg View Post
    Array formula: =AVERAGE(IF(B1:B20>0, B1:B20 / A1:A20))
    Hey, that's much closer. I don't want to limit it to rows 1-20, though. However, when I took out all the row number references:

    Please Login or Register  to view this content.
    it didn't work. Should I just change the 20 to something really big (e.g. - 10000000) and just deal with it or is there a better way?

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

    Re: Conditional weighted average

    Use dynamic named ranges. You don't want Excel unnecessarily evaluating whole columns.

  7. #7
    Registered User
    Join Date
    04-20-2009
    Location
    Internet
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Conditional weighted average

    Quote Originally Posted by saturnexcel View Post
    Hey, that's much closer. I don't want to limit it to rows 1-20, though. However, when I took out all the row number references:

    Please Login or Register  to view this content.
    it didn't work. Should I just change the 20 to something really big (e.g. - 10000000) and just deal with it or is there a better way?
    Oh wait, I think I had problems because my first row has header info in it. I need something like B2:BMAX. Does such a thing exist?

  8. #8
    Registered User
    Join Date
    04-20-2009
    Location
    Internet
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Conditional weighted average

    Quote Originally Posted by shg View Post
    Use dynamic named ranges. You don't want Excel unnecessarily evaluating whole columns.
    Ok, I will look into that. Thanks!

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

    Re: Conditional weighted average

    You’re welcome. Would you please mark the thread as Solved?

    Click the Edit button on your first post in the thread

    Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes

+ 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