Excel Tutorial
Excel tutorials, quizzes & AI guides — all levels
RSS
  • Online Excel Exercises
  • Training
  • Excel Tests
  • Sitemap
  • Premium Quizzes
  • Shop
  • My account

Transform List to Matrix like Distance Table 🚗

Lookup functions
Reading time: 2 minutes
Views: 8,234

Learn how to turn a list of names, products, or cities into a data matrix. Cross-check each item to create a table like the one below 👍

How to create a distance table presentation

Distance Between Cities

This example shows distances between cities in Europe. Notice that the order of cities in the columns doesn’t matter—one entry is enough 😉

Distance between cities in Europe

Step 1: Extract Unique City Names

First, focus on the City 1 column. Since City 1 and City 2 have the same data, we only need one. Use the UNIQUE function in Excel 365 and 2021 to remove duplicates, and the SORT function to organize them.

Extract unique city names from column City 1

Step 2: Transpose the Column

Next, use the TRANSPOSE function to change the result from vertical to horizontal. The # symbol returns all cells from the UNIQUE function.

Transpose result of UNIQUE function

Step 3: Create the Matrix Formula

Now, we build the main formula to turn a list into a matrix. It compares cities in the source table and outputs results.

  1. ((tbl_Dist[City1]=F$1)*(tbl_Dist[City2]=$E2))
    • This checks if City1 in tbl_Dist matches F$1 and if City2 matches $E2.
    • tbl_Dist[City1]=F$1 and tbl_Dist[City2]=$E2 create TRUE/FALSE arrays.
    • Multiplying these arrays gives a 1 when both are TRUE, otherwise 0.
  2. ((tbl_Dist[City1]=$E2)*(tbl_Dist[City2]=F$1))
    • This checks for the reverse city order (City1 is $E2, City2 is F$1).
    • This ensures distance is found regardless of city order.
  3. ((tbl_Dist[City1]=F$1)*(tbl_Dist[City2]=$E2))+((tbl_Dist[City1]=$E2)*(tbl_Dist[City2]=F$1))
    • The + operator combines the results, giving 1 if either condition is TRUE.
  4. MATCH(1, …, 0)
    • This function locates the row with matching cities (F$1 and $E2).
    • MATCH finds the first 1 in the array, identifying the matching city pair.
  5. INDEX(tbl_Dist[Distance(km)], …)
    • INDEX returns the distance from tbl_Dist[Distance(km)] at the MATCH position.
  6. IFERROR(…, “-“)
    • IFERROR shows a hyphen (“-“) if no match is found, instead of an error.

Copy this formula across each cell in the Distance Matrix.

Formula to create a distance matrix from a list
  • We applied a color scale to highlight distances using conditional formatting.

Frédéric LE GUEN

INDEX, logical test

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Viewed Posts

  • Displaying Negative Numbers in Parentheses in Excel (310,065)
  • Top 10 Excel Functions You Must Know (232,001)
  • How to make automatic calendar in Excel (212,775)
  • Dash for a zero in Excel automatically (190,812)
  • Converting a Date from YYYYMMDD to DD/MM/YYYY in Excel (171,033)
image excel exercises
Excel Exercises
image excel quizzes
Excel Quizzes

Transform List to Matrix like Distance Table 🚗

Reading time: 2 minutes
Views: 8,234

Learn how to turn a list of names, products, or cities into a data matrix. Cross-check each item to create a table like the one below 👍

How to create a distance table presentation

Distance Between Cities

This example shows distances between cities in Europe. Notice that the order of cities in the columns doesn’t matter—one entry is enough 😉

Distance between cities in Europe

Step 1: Extract Unique City Names

First, focus on the City 1 column. Since City 1 and City 2 have the same data, we only need one. Use the UNIQUE function in Excel 365 and 2021 to remove duplicates, and the SORT function to organize them.

Extract unique city names from column City 1

Step 2: Transpose the Column

Next, use the TRANSPOSE function to change the result from vertical to horizontal. The # symbol returns all cells from the UNIQUE function.

Transpose result of UNIQUE function

Step 3: Create the Matrix Formula

Now, we build the main formula to turn a list into a matrix. It compares cities in the source table and outputs results.

  1. ((tbl_Dist[City1]=F$1)*(tbl_Dist[City2]=$E2))
    • This checks if City1 in tbl_Dist matches F$1 and if City2 matches $E2.
    • tbl_Dist[City1]=F$1 and tbl_Dist[City2]=$E2 create TRUE/FALSE arrays.
    • Multiplying these arrays gives a 1 when both are TRUE, otherwise 0.
  2. ((tbl_Dist[City1]=$E2)*(tbl_Dist[City2]=F$1))
    • This checks for the reverse city order (City1 is $E2, City2 is F$1).
    • This ensures distance is found regardless of city order.
  3. ((tbl_Dist[City1]=F$1)*(tbl_Dist[City2]=$E2))+((tbl_Dist[City1]=$E2)*(tbl_Dist[City2]=F$1))
    • The + operator combines the results, giving 1 if either condition is TRUE.
  4. MATCH(1, …, 0)
    • This function locates the row with matching cities (F$1 and $E2).
    • MATCH finds the first 1 in the array, identifying the matching city pair.
  5. INDEX(tbl_Dist[Distance(km)], …)
    • INDEX returns the distance from tbl_Dist[Distance(km)] at the MATCH position.
  6. IFERROR(…, “-“)
    • IFERROR shows a hyphen (“-“) if no match is found, instead of an error.

Copy this formula across each cell in the Distance Matrix.

Formula to create a distance matrix from a list
  • We applied a color scale to highlight distances using conditional formatting.
Tags: INDEXlogical test

Frédéric LE GUEN

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Contact us
About me 
Privacy Policy

© 2022 – 2026 – excel-tutorial.com. All Rights Reserved.
Excel Tutorial is managed by majordome du net

Contact us
About me 
Privacy Policy

© 2022 – 2026 – excel-tutorial.com. All Rights Reserved.
Excel Tutorial is managed by majordome du net