+ Reply to Thread
Results 1 to 2 of 2

How does this formula work? (SUMPRODUCT(LOOKUP(ROW(INDIRECT(C$4&":"&EOMONTH(C$4,0))

  1. #1
    Registered User
    Join Date
    01-13-2011
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2010
    Posts
    87

    How does this formula work? (SUMPRODUCT(LOOKUP(ROW(INDIRECT(C$4&":"&EOMONTH(C$4,0))

    A number of months ago, someone very graciously designed the following formula:
    =(SUMPRODUCT(LOOKUP(ROW(INDIRECT(C$4&":"&EOMONTH(C$4,0)))+6,'CJNH 2012'!$3:$3,'CJNH 2012'!155:155))/7)

    This is used to calculate monthly payroll accruals. So, in row 3 in CJNH 2012 there are dates, e.g. 2/4/12, 2/11/12, 2/18/12, 2/25/12, 3/3/12

    If C4 = 2/1/2012, this formula will add 4/7ths of the cell in row 155 sharing the same column as 2/4/12, the entirety of the cell in row 155 sharing the same column as 2/11/12, 2/18/12 and 2/25/12, and 3/7ths of the cell in row 155 sharing the same column as 3/3/12. This formula does the calculation perfectly, but I can't figure out why it works. And even though I was satisfied for a while that it does exactly as its supposed to do, I'm at the point now where I'd really like to know the logic behind it.

  2. #2
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: How does this formula work? (SUMPRODUCT(LOOKUP(ROW(INDIRECT(C$4&":"&EOMONTH(C$4,

    INDIRECT(C$4&":"&EOMONTH(C$4,0)) will turn into a range of rows based on the numeric value of the date in C4 and the End of Month date of C4. For 2/1/2012 it would be INDIRECT("40940:40968") from there we end up with ROW("40940:40968")+6, which will give us a range of "40946:40974" to use as our LOOKUP value (imagine each value from 40946 to 40974 listed as an array). The LOOKUP vector is 'Sheet CJNH 2012'!3:3 which we know contains 2/4/12, 2/11/12, 2/18/12, 2/25/12, 3/3/12. Those equate to number values of 40943, 40950 ,40957, 40964, 40971. If the LOOKUP function can't find the LOOKUP value, the function matches the largest value in LOOKUP vector that is less than or equal to LOOKUP value. So in the array {40946, 40947, 40948, 40949, 40950, 40951, 40952, 40953, 40954, 40955, 40956, 40957, 40958, 40959, 40960, 40961, 40962, 40963, 40964, 40965, 40966, 40967, 40968, 40969, 40970, 40971, 40972, 40973, 40974} 40946 finds 40943 (date value of 2/4/2012); 40947 finds 40943; 40948 finds 40943; and 40949 finds 40943. Because your LOOKUP result is 'Sheet CJNH 2012'!155:155, it will use the data from that row (in the corresponding column to row 3). If the value in the column where 2/4/2012 intersects row 155 is 1, then this part of the formula would result in 4 (1+1+1+1). If you keep moving down the long array list (we're at 40950); 40950 finds 40950; 40951 finds 40950; 40952 finds 40950; 40953 finds 40950; 40954 finds 40950; 40955 finds 40950; and 40956 finds 40950. Again if the values in row 155 were 1, you'd result in 7 (1+1+1+1+1+1+1). If you keep going through the long array list and adding the values from row 155 and then divide the total sum by 7, you should get the result from the formula you posted.

    Hopefully this helps a bit
    -Greg If this is helpful, pls click Star icon in lower left corner

+ 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