+ Reply to Thread
Results 1 to 3 of 3

Average over a text range using a vlookup

  1. #1
    Registered User
    Join Date
    10-22-2009
    Location
    Amsterdam, Holland
    MS-Off Ver
    Excel 2003
    Posts
    2

    Average over a text range using a vlookup

    I have attached a very simple spreadsheet to show what I am trying to achieve.

    I have a sheet with traffic-light conditions: g (green), a (amber) and r (red). So, for instance, I have a row with the following traffic-lights:
    a g r a g

    Now I want to do some calculations with these traffic-light conditions so I create a v-lookup table:
    g 5
    a 4
    r 0


    This would mean that the row would now read:
    4 5 0 4 5

    So far so good. Now I want the average of this row. Usually this is easy, I just do a =AVERAGE(A1:E1) which would give me a result of 3.6. But because there a not actual values but text values which are translated by a vlookup So I would need to do a
    =AVERAGE(VLOOKUP(A1;H1:I3;2;FALSE);VLOOKUP(B1;H1:I3;2;FALSE);VLOOKUP(C1;H1:I3;2;FALSE);VLOOKUP(D1;H1:I3;2;FALSE);VLOOKUP(E1;H1:I3;2;FALSE)) which gives me the expected result of 3.6. Although this works it quickly becomes rather messy when I have thousands of rows that contain hundreds of traffic-light conditions for each row.

    So, and here is my question, why can't I specify a range. So something like:
    AVERAGE(VLOOKUP(A2;H1:I3;2;FALSE);VLOOKUP(E2;H1:I3;2;FALSE)). If I try this I get an error. So, what can I do? Or is there another way to achieve this?
    Attached Files Attached Files
    Last edited by hemd; 10-22-2009 at 05:40 AM. Reason: Changed status to [SOLVED]

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

    Re: Average over a text range using a vlookup

    Your formula would be something like

    F1: =SUMPRODUCT(($A1:$E1=$H$1:$H$3)*($I$1:$I$3))/COUNTA($A1:$E1)
    copied down as required

    or without the lookup table

    F1: =SUM(COUNTIF($A1:$E1;{"r","a","g"})*{0,4,5})/COUNTA($A1:$E1)
    obviously if red is always 0 you can remove the test and associated value (0) - left for demo.
    Last edited by DonkeyOte; 10-22-2009 at 05:37 AM.

  3. #3
    Registered User
    Join Date
    10-22-2009
    Location
    Amsterdam, Holland
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Average over a text range using a vlookup

    Wow, that's quick. And SOLVED the problem.

    I'm a happy man

+ 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