2D Match - Index and Match with more tha one row.

Penacare

New Member
Joined
May 11, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am looking for a way to use a lookup values to match the Chemical concentration with its respective Sample#: For Chemical 1 to 9 I don't have a problem, I can easily use 2D lookup Match& Index. However, for Chemical 10 and Chemical 11 this won't work as there are several rows. I could simply manually put all the values in one row. However, there are many chemicals o tha twill take a long time. Any help will be appreciated.


1652276350699.png
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Is there any reason to keep the concentrations on different rows for the same chemical? I'm assuming the table values are measurement results?...Do the different rows indicate different dates, measurement methods, labs, operators, etc.? It would be more convenient to transform the table into single rows per chemical, which could be done easily in Power Query, but a clearer idea about the objective would be helpful. What are you trying to match...e.g., what information is known, and what do you want the formula to return?
 
Upvote 0
Thanks, for the reply. Yes, you are correct there are multiple rows for certain chemicals as some might be obtained using different methods or were measured in different dates. This information is provided by the Lab. SO I dont have control on how they provide the data.

What I am trying to create is a easier way to populate my own design tables by using an index match formula so I dont have to go over the 100s reports and do it manually. I want to create a sheet where I can just by copy and paste the lab report and it will automatically populate my tables.

Regards.
 
Upvote 0
One idea is to revise the table structure entirely in an effort to flatten it further. But it sounds as if your needs from the table may not depend on the details that led to the information being placed on different rows to begin with. Another approach is to take the table provided, drop it into a formal Excel table and use Power Query to transform it into a flatter structure so that conventional lookup formulas can be used. I took a representative sample of your input data, converted it to an Excel table (by clicking anywhere in the data and hitting Ctrl-t and indicating that the table has headers). Then I created a Power Query script that effectively merges the rows, transforming this initial table:
MrExcel_20220511.xlsx
ABCDEFGHIJK
1ChemicalSample 1Sample 2Sample 3Sample 4Sample 5Sample 6Sample 7Sample 8Sample 9Sample 10
2Chemical 1<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5
3Chemical 2<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4
4Chemical 3<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5
5Chemical 4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4
6Chemical 5<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3
7Chemical 6<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4
8Chemical 7<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3
9Chemical 872767178787175768070
10Chemical 9<30<30<30<30<30<30<30<30<30<30
11Chemical 10<0.01<0.01<0.01<0.01<0.01<0.01<0.01<0.01
12<0.5<0.5
13Chemical 112391020
14102011401290
15750
161190291463236
17Chemical 12<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5
SourceData

...into this:
MrExcel_20220511.xlsx
ABCDEFGHIJK
1ChemicalSample 1Sample 10Sample 2Sample 3Sample 4Sample 5Sample 6Sample 7Sample 8Sample 9
2Chemical 1<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5
3Chemical 10<0.01<0.01<0.01<0.01<0.01<0.01<0.5<0.5<0.01<0.01
4Chemical 1110201010119011407502911290463236239
5Chemical 12<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5
6Chemical 2<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4
7Chemical 3<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5<0.5
8Chemical 4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4
9Chemical 5<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3
10Chemical 6<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4<0.4
11Chemical 7<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3<0.3
12Chemical 872707671787871757680
13Chemical 9<30<30<30<30<30<30<30<30<30<30
Transformed

The M-code for doing this, for the main body, Query Table1:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Chemical", type text}, {"Sample 1", type any}, {"Sample 2", type any}, {"Sample 3", type any}, {"Sample 4", type any}, {"Sample 5", type any}, {"Sample 6", type any}, {"Sample 7", type any}, {"Sample 8", type any}, {"Sample 9", type any}, {"Sample 10", type any}}),
    #"Filled Down" = Table.FillDown(#"Changed Type",{"Chemical"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filled Down", {"Chemical"}, "Attribute", "Value"),
    #"Sorted Rows" = Table.Sort(#"Unpivoted Other Columns",{{"Chemical", Order.Ascending}, {"Attribute", Order.Ascending}, {"Value", Order.Ascending}}),
    #"Appended Query" = Table.Combine({#"Sorted Rows", Columns}),
    #"Removed Duplicates" = Table.Distinct(#"Appended Query"),
    #"Pivoted Column" = Table.Pivot(#"Removed Duplicates", List.Distinct(#"Removed Duplicates"[Attribute]), "Attribute", "Value"),
    #"Filtered Rows1" = Table.SelectRows(#"Pivoted Column", each ([Chemical] <> null)),
    #"Sorted Rows1" = Table.Sort(#"Filtered Rows1",{{"Chemical", Order.Ascending}})
in
    #"Sorted Rows1"
And for the column headings needed in an append operation, Query Columns:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each ([Chemical] <> null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Chemical"}),
    #"Demoted Headers" = Table.DemoteHeaders(#"Removed Columns"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Demoted Headers",{{"Column1", type any}, {"Column2", type any}, {"Column3", type any}, {"Column4", type text}, {"Column5", type text}, {"Column6", type any}, {"Column7", type any}, {"Column8", type text}, {"Column9", type any}, {"Column10", type any}}),
    #"Kept First Rows" = Table.FirstN(#"Changed Type1",1),
    #"Transposed Table" = Table.Transpose(#"Kept First Rows"),
    #"Added Custom" = Table.AddColumn(#"Transposed Table", "Chemical", each null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Value", each null),
    #"Renamed Columns" = Table.RenameColumns(#"Added Custom1",{{"Column1", "Attribute"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Chemical", "Attribute", "Value"})
in
    #"Reordered Columns"
A working sample file is here, if you'd like to try it out. Once new information is added to the table on the SourceData sheet, hit Data>Refresh All to generate a new output table on the Transformed sheet.
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,658
Latest member
GStorm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top