# LOOKUP FORMULA BASED ON HEADERS

Copper Contributor

# LOOKUP FORMULA BASED ON HEADERS

Hello,

I have some data, which consists of account numbers (rows) by month (headers).

I'm attempting to create a formula that will return the value of a cell based on the date I enter. For example, if I enter Nov 20, I want the formula to search for that date in the headers and return the values of the account numbers in that column, for Nov 20.

So far I have tried using INDEX & MATCH, VLOOKUP with an MATCH function and SUMIFS, but none of these have worked.

Could anyone suggest any other formulas which may work?

Thanks

15 Replies

# Re: LOOKUP FORMULA BASED ON HEADERS

An actual sample of the spreadsheet itself is better than an image, and would also enable somebody here to write a formula that works and post it for you to use.

# Re: LOOKUP FORMULA BASED ON HEADERS

I have included an example of the spreadsheet, as requested.

I am trying to populate the cells of column N, with the values in column I. I want to use the date in cell P1, as the search criteria. So any the values of any cells contained within a column, where the dates agree are shown in column N.

If you need any further information, please let me know.

Thank you.

# Re: LOOKUP FORMULA BASED ON HEADERS

Enter this formula in cell N2, and copy it down.

=INDEX(B2:M2,,MATCH(\$P\$1,\$B\$1:\$M\$1,0))

To explain the formula: the MATCH function finds the column number in the array of headings that matches your date in P1   The dollar signs keep the references constant even as the total formula is copied to succeeding rows.

The INDEX function uses that number to find the corresponding column in each row as the formula is copied down to succeeding rows.

Let me know if this is in fact doing what you want. I'm curious what the actual application is here. It seems an unusual way to organize the information...so I'm wondering whether the whole spreadsheet or workbook could use a makeover. But of course, it's not my business so feel free to ignore the question.

# Re: LOOKUP FORMULA BASED ON HEADERS

Brilliant, this is now working! When I was using the INDEX & FUNCTION before, I was selecting the entire array, so that must of been why it didn't work.

The application is for use within an a financial statement report. The example I sent shows how the TB data would be formatted within the report.

I'm trying to set it up, so when the user enters the relevant period end date, the formulas will automatically pull in the correct data for the relevant period.

I'm in the process of giving all worksheets and workbooks an efficiency drive makeover, so any input would be very welcome.

# Re: LOOKUP FORMULA BASED ON HEADERS

I'm in the process of giving all worksheets and workbooks an efficiency drive makeover, so any input would be very welcome.

Well, without knowing a lot more it would be entirely presumptuous to offer suggestions. Who the user(s) is (are) going to be for example.

In general, though, the layout you had seemed less than functional for the long term. To keep adding monthly data as a new column works for a while, but there is a limit to columns; and long before that, just navigating the screen becomes unwieldly.

Most databases are better thought of as rows and rows of data with the different fields of distinct types of data reflected in the columns. A set of rows, with both account number and month as separate fields in each row (along with other monthly data) would still be searchable and amenable to summarization by account, by month, by other characteristics ...

# Re: LOOKUP FORMULA BASED ON HEADERS

Bit more modern variant

``=XLOOKUP(\$P\$1, \$B\$1:\$M\$1, B2:INDEX(M:M,XMATCH(,A:A)-1))``

# Re: LOOKUP FORMULA BASED ON HEADERS

I suggest this formula in O2 of the attached version of your file:

``````=INDEX(ColumnsLeft,

ColumnsLeft refers to:

``=Schedule!\$B2:N2``

``=Schedule!\$B\$1:N\$1``

Kindly notice these:

1. I modified the formula starting in C1 to this:

``=EOMONTH(B1,1)``

2. I inserted a column for April 2021, with simulated values thereunder.

3. You can also insert a column for May 2021 to test the dynamic attribute of ColumnsLeft and HeadersLeft.

# Re: LOOKUP FORMULA BASED ON HEADERS

Thank you very much for this example.

This formula will certainly help a lot with making my spreadsheets more dynamic.

# Re: LOOKUP FORMULA BASED ON HEADERS

You're very much welcome!

# Re: LOOKUP FORMULA BASED ON HEADERS

Thank you for this formula.  One question; I never clearly understood why in some scenarios we have to put two comma's before the match function in this lookup formula.

Thank you,

Phil

# Re: LOOKUP FORMULA BASED ON HEADERS

Thank you for this formula.  One question; I never clearly understood why in some scenarios we have to put two comma's before the match function in this lookup formula.

Assuming your "this formula" is referring to this formula:

=INDEX(B2:M2,,MATCH(\$P\$1,\$B\$1:\$M\$1,0))

The reason for the two commas is that after only one comma the value returned by your MATCH refers to a row; after the second comma, it refers to a column.  Here is a link that more fully explains the INDEX function, which is the one where it's relevant.

# Re: LOOKUP FORMULA BASED ON HEADERS

Is this something you think would work here? I have tried using the formula but have not had any luck. Basically we just need to copy these items across to another sheet but due to the columns not lining up (hidden columns in the top sheet throwing out the basic formula), it is causing some issues.

# Re: LOOKUP FORMULA BASED ON HEADERS

Is this something you think would work here?

It's not altogether clear what "this" refers to. Presumably the part of the formula that refers to headers.

I have tried using the formula but have not had any luck. Basically we just need to copy these items across to another sheet but due to the columns not lining up (hidden columns in the top sheet throwing out the basic formula), it is causing some issues.

I have no doubt that something could work, but it would be a lot easier to figure it out if we could see the actual spreadsheets (or, if actuals contain confidential data, a mockup of them containing false data but representing the situation accurately. Post copies on OneDrive or GoogleDrive and paste a link here that grants access.

Seeing the actual helps in understanding the bigger picture--how data are organized, etc--and because Excel always has multiple effective routes from A to B, the bigger picture helps determine which route (which function, which formulas) make most sense.

# Re: LOOKUP FORMULA BASED ON HEADERS

Ok see the attached sheets. Basically trying to do the below.

QLDMaintenance>P94 to equal RevenueALL>AU109

Then

QLDMaintenance>V94 to equal RevenueALL>AV109

and so on

As columns have been added the the QLDMaintenance sheet, it is difficult to simply copy/paste the formula so was hoping to use the Header option but as you said, I could be overthinking it (which I do tend to do...).

Thanks

# Re: LOOKUP FORMULA BASED ON HEADERS

Chris -- after looking at these two workbooks, I'm somewhat overwhelmed. For the specific task you're asking about--even recognizing that the idea is to get those numbers all the way down to column CA in the "RevenueAll" sheet--I would suggest you not try to write a single formula that can be copied. With both workbooks open at the same time, it was easy to just enter the equal sign in the target sheet, cell AU109, click on the source sheet, and end up with

='[QLDMainteance.xlsx]QLD | Forecast'!\$P\$95

You could do the same steps for each of the 24 or 36 or 48 cells and be done. It would take a little bit of time, but no more than you've already spent looking for a single formulaic approach.

That said, though, here's my real concern: your overall design contains SO MANY redundancies, SO MANY cells referring to cells in other columns or other rows and simply bringing over the value from that source, which brought it over from yet another, which brought it over from yet another...and so on ad infinitum. Well, not quite ad infinitum, but you get the point, I hope.

And now you're trying to do the same--bring over a number that's already been brought forward multiple times, just, this time, into another workbook.

It's fundamentally, in my opinion, not a good overall design.

It may work.

But it has the appearance of an Excel spreadsheet that was designed based on an extensive paper-based ledger sheet accounting and project management process. That is, it uses Excel to add, subtract, multiple--do basic math--but it's incredibly labor intensive, very inefficient, in doing so. So it would appear.

I realize this could be an erroneous impression. But if we were sitting down face-to-face, I'd be wanting to learn more what all the inputs are, then the outputs (reports, etc), and would then be suggesting that you find a good spreadsheet designer who could help you take advantage of Excel's marvelous abilities to take well organized (i.e., non-redundant) raw data at the input end, and extract/slice/dice/combine for useful output.   (By the way, that would not be me; I'm long retired, neither looking for nor needing extra work.)

It's not advice you were looking for, and you are certainly not obligated to take it. I can't in good conscience, though, not give you that feedback.