0

Say I have a table "Data" (created with the "Format as table" button, with headers). In another table (say "Table"), I have a column ("Target column") that has values in the column names of the "Data" table and a column "Median". In the "Median" column, I want to have the median value of the column that is given in the "Target column" column of table "Data".

I tried to do Median(Data[A2]) where A is the column index for the "Target column" column. This of course doesn't work. I suppose something like it could work with INDIRECT, but I'm not sure that's the most performant solution.

Say my table "Data" has columns "val1", "val2", "val3" and my table "Table" I have columns "Target column", "Median". For any column name of table "Data" in the "Target column", I want to have the median of that column in the table "Data" in the column "Median" of the table "Table".

1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Dec 5, 2022 at 13:42

1 Answer 1

1

Either of these should work:

This searches the header row of the Data table for the heading you've entered in the Target column of your Table table. It then uses the result of that to return the correct column from the Data table and calculates the median for that.

=MEDIAN(INDEX(Data,,MATCH([@Target],Data[#Headers],0)))  

or

This creates a text version of the formula you need to reference the column, INDIRECT then changes it to a formula that you can use MEDIAN on.

=MEDIAN(INDIRECT("Data[" & [@Target] & "]"))

The first one would be preferable as it's not volatile - i.e. it won't recalculate whenever anything changes in the workbook.

1
  • 1
    Tested the first one, works like an absolute charm :) Commented Dec 5, 2022 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .