简体   繁体   中英

How to: dynamically select a table field name in a formula based upon a value set in a cell outside the table

I have a table [TABLE1] in an Excel spreadsheet that begins in cell A3. That table is structured as follows:

Classification Task Description Q1 Q2 Q3 Q4 Select
Class1 Task 1 5 3
Class1 Task 2 2 1
Class2 Task 3
Class3 Task 4 1 1

The [Select] column is intended to be used to filter the values I'm interested in. It should contain a simple boolean (True/False) value. I'm able to accomplish this by setting a formula for the [Select] column to something like this:

=NOT(ISBLANK(@[Q1]))

The goal is to be able to "change" the formula without having to manually edit the formula (ie I want to protect this cell so others can't muck up the formula), so what I want to do is to change that formula dynamically by specifying the quarter I want to see the data for in cell B1 (eg, set B1 to 1 for Q1, 2 for Q2, etc.). Then, I should be able to filter out the "False" values in the [Select] Column to reduce the visible rows to what I'm actually interested in.

That should change the formula to something like:

=NOT(ISBLANK(INDIRECT("@[Q" & VALUETOTEXT(B1) & "]")))

but this doesn't seem to work.

NOTE: My actual scenario is slightly more complicated -- the formula in the select column is actually looking at values from 3 different table columns -- 2 that I always want to look at if they're not blank and 5 other columns that I want to be able to switch between based upon the value in cell B1. I've simplified the issue for this question.

Another (non-volatile) way to approach it is:

=NOT( ISBLANK( INDEX( Table1[@[Q1]:[Q4]], 1, $B$1 ) ) )

Try INDEX() then return column based on value of B1 cell.

=ISBLANK(@INDEX(Table1[[Q1]:[Q4]],,B$1))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM