Searching across a record
Hi I have a question about retrieving data based on the relative column positioning within a record.
This relates to data on investment proposals. The values are not complex, but what is challenging is the uncertain (random) positioning of the desired value within the retrieved records.
I would like to focus initially on using Excel functions such as XLOOKUP. I have tried using LET/XLOOKUP/XMATCH but have found the syntax difficult. I am aware that is may be possible to solve this problem with PowerQuery.
First we have a PRESENTATION SPREADSHEET (tab) with the following structure. Also included here are example values (to be retrieved). Currently only the Reference is known.
Reference Assessor_1 Assessor_1_Score Assessor_2 Assessor_2_Score
0001 James Number? Mark Number?
0007 James Number? Robert Number?
Second we have a data spreadsheet (downloaded from a web form) with the following structure. It is possible that there may be additional data columns between Assessor name and score, for example the employer of the Assessor.
Reference Assessor_A Assessor_A_Score Assessor_B Assessor_B_Score
0001 Mark 5.1 James 4.7
0007 James 3.2 Robert 5.5
Following the use of appropriate Excel formulas the PRESENTATION SPREADSHEET will look as follows.
Reference Assessor_1 Assessor_1_Score Assessor_2 Assessor_2_Score
0001 James 4.7 Mark 5.1
0007 James 3.2 Robert 5.5
RE: Searching across a record
Hi Matthew,
Thank you for the forum question.
Yes, this can be solved using Excel formulas, and LET, XLOOKUP, XMATCH and INDEX are a good combination.
The important point is that you need to identify the correct score using two criteria:
1. The Reference, which identifies the correct record.
2. The Assessor name, which identifies the correct position within that record.
The formula must also work if additional columns, such as Assessor Employer, appear between the assessor's name and score.
1. Example spreadsheet structure
Presentation sheet
A: Reference B: Assessor_1 C: Score D: Assessor_2 E: Score
0001 James ? Mark ?
0007 James ? Robert ?
Data sheet
A: Reference B: Assessor_A C: Assessor_A_Score D: Assessor_B E: Assessor_B_Score
0001 Mark 5.1 James 4.7
0007 James 3.2 Robert 5.5
2. Recommended Excel formula
Assuming the downloaded data is on a worksheet named Data, enter this formula in Presentation!C2:
=IFERROR(
LET(
r,XLOOKUP($A2,Data!$A$2:$A$1000,Data!$B$2:$Z$1000),
h,Data!$B$1:$Z$1,
p,XMATCH(B2,r,0),
INDEX(r,1,XMATCH(INDEX(h,1,p)&"_Score",h,0))
),
"Not found"
)
Copy the formula down column C.
You can also copy it across to column E, where it will automatically use the assessor name in column D.
3. How the formula works
The LET function allows us to divide the calculation into three stages.
Stage 1: Find the correct record
r,XLOOKUP($A2,Data!$A$2:$A$1000,Data!$B$2:$Z$1000)
This retrieves the entire matching record from the downloaded data, excluding the Reference column.
Stage 2: Find the assessor's position
p,XMATCH(B2,r,0)
This searches the retrieved record for the assessor's name.
For reference 0001, James is in the third position of the retrieved data.
Stage 3: Retrieve the corresponding score
INDEX(r,1,XMATCH(INDEX(h,1,p)&"_Score",h,0))
This identifies the column heading associated with James, adds _Score, and retrieves the value from that column.
This is particularly useful because it does not assume that the score is immediately next to the assessor's name.
4. What happens if additional columns are inserted?
Suppose the downloaded data changes to:
Reference Assessor_A Assessor_A_Employer Assessor_A_Score Assessor_B Assessor_B_Employer Assessor_B_Score
0001 Mark ABC Ltd 5.1 James XYZ Ltd 4.7
0007 James DEF Ltd 3.2 Robert GHI Ltd 5.5
The formula will still work, provided:
• Each assessor column has a unique heading such as Assessor_A.
• Its corresponding score column is named Assessor_A_Score.
• All relevant columns are included in the specified range.
• Assessor names uniquely identify the intended assessor within each record.
5. Final result
Your Presentation sheet will display:
Reference Assessor_1 Assessor_1_Score Assessor_2 Assessor_2_Score
0001 James 4.7 Mark 5.1
0007 James 3.2 Robert 5.5
My recommendation
For this particular problem, I would initially use LET + XLOOKUP + XMATCH + INDEX rather than Power Query.
The formula is relatively compact, and the logic is straightforward once you understand its individual components.
However, there is one important distinction:
• If the assessor names can change positions but the column headings remain consistent, this formula is suitable.
• If both the column headings and their positions can change unpredictably, we would need a more flexible approach.
The main improvement over a simple XLOOKUP is that the formula identifies the correct score column by its heading rather than relying on its physical position.
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector


