英文:
Dynamic rate tables: How to change multiplied cell by drop down list
问题
我的目标是将两个用户输入的值返回的平均值与两个表格中的唯一费率相乘。
销售号 | 销售额 | 平均票价 | 费率 | AX费率 | MR费率 |
---|---|---|---|---|---|
100 | $10,000 | $100 | ? | ? | ? |
我有两个下拉列表:第一个代表两个表格(表格1和表格2),第二个代表表格1和表格2中的列(医疗保健,教育等)。
表格1 | 医疗保健 | 教育 |
---|---|---|
费率 | 2.00% | 3.00% |
AX费率 | 2.50% | 4.00% |
MR费率 | 3.00% | 4.50% |
表格2 | 医疗保健 | 教育 |
---|---|---|
费率 | 2.50% | 3.50% |
AX费率 | 3.00% | 4.50% |
MR费率 | 3.50% | 5.00% |
我希望当用户从第一个下拉列表中选择“表格1”并从第二个下拉列表中选择“医疗保健”时,它将调用表格1 - 医疗保健单元格中的费率,将Avg.tkt乘以表格1 - 医疗保健列中的费率(即2.00% x $100),并将其返回到新单元格中。
我已经通过嵌套的IF语句实现了这个目标:
=IF(C4="Table1",IF(C5="Healthcare",D31*J7,IF(C5="Education",D31*K7,C5="Charity",D31*L7),IF(C4="Table2",IF(C5="Healthcare",D31*J7,IF(C5="Education",D31*K7,C5="Charity",D31*L7)))))
但我想知道是否有更有效的方法来产生这些结果?我想减少嵌套IF语句的使用(或者至少减少数量)。
英文:
My goal is to have an average value (returned by 2 user inputted values) to be multiplied by a unique rate that is from either of 2 tables.
Sales # | Sales $ | Avg.Tkt | Rate | AX Rate | MR Rate |
---|---|---|---|---|---|
100 | $10,000 | $100 | ? | ? | ? |
I have 2 drop-down lists: The 1st representing 2 tables (Table 1 & Table 2) and the 2nd representing the columns withing Tables 1 & Tables 2 (Healthcare, Education, Etc.)
Table 1 | Healthcare | Education |
---|---|---|
Rate | 2.00% | 3.00% |
AX Rate | 2.50% | 4.00% |
MR Rate | 3.00% | 4.50% |
Table 2 | Healthcare | Education |
---|---|---|
Rate | 2.50% | 3.50% |
AX Rate | 3.00% | 4.50% |
MR Rate | 3.50% | 5.00% |
I want it to when a user selects "Table 1" from the 1st drop-down list and "Healthcare" from the 2nd drop-down list it will call the rate in Table 1 - Healthcare cell multiply the Avg.tkt by the rate from Table 1 - Healthcare column (i.e. 2.00% x $100) and return it in a new cell.
I've already achieved this by nest IF statements:
=IF(C4="Table1",IF(C5="Healthcare",D31*J7,IF(C5="Education",D31*K7,C5="Charity",D31*L7),IF(C4="Table2",IF(C5="Healthcare",D31*J7,IF(C5="Education",D31*K7,C5="Charity",D31*L7)))))
But would like to know if there is a more efficient way of producing these results?
I would like to reduce the use of nesting IF statements (or at least cut down on the amount).
答案1
得分: 1
如果您不想或无法像另一个建议中提到的那样将表格合并在一起,您可以使用一个 IF 语句,并嵌套一个 INDEX 和 MATCH 公式:
=IF($B$4="Table 1",INDEX($A$7:$C$10,MATCH(D$1,$A$7:$A$10,0),MATCH($B$5,$A$7:$C$7,0)),INDEX($A$12:$C$15,MATCH(D$1,$A$12:$A$15,0),MATCH($B$5,$A$12:$C$12,0)))
这将检查所选的表格是否为 Table 1。如果是,它会在 Table 1 数据范围内查找特定行业的费率指标。如果下拉菜单不是 Table 1,那么它将是 Table 2,因此它会在 Table 2 数据范围内进行相同的查找。
英文:
If you don't want to or can't join the tables together as another answer suggested, you could use an IF statement and nest an INDEX and MATCH formula within:
=IF($B$4="Table 1",INDEX($A$7:$C$10,MATCH(D$1,$A$7:$A$10,0),MATCH($B$5,$A$7:$C$7,0)),INDEX($A$12:$C$15,MATCH(D$1,$A$12:$A$15,0),MATCH($B$5,$A$12:$C$12,0)))
This checks whether the table selected is Table 1. If it is then it looks up that rate metric for that specific industry in the Table 1 range of data. If the dropdown is not Table 1, it is Table 2 so it does the same lookup but for the Table 2 range of data.
答案2
得分: 1
在Excel中,有许多方法可以解决问题。可以使用INDIRECT()
函数与表名来完成,但可以避免使用INDIRECT()
,因为它是单线程的,这样会破坏Excel的多线程计算引擎。我仍然会分享这个解决方案以及其他方法,您可以尝试选择最适合您查询的方法。
方法一: --> 使用INDIRECT()
和TOROW()
• 单元格H4
中使用的公式 --> 它会向右扩展!
=TOROW(INDIRECT(E1&"[&]"&F1))
• 或者,单元格H9
中使用的公式 --> 没有#SPILL!
--> 需要向右填充!
=INDEX(INDIRECT($E$1&"[&]"&$F$1),COLUMN(A1))
方法二: --> 使用XLOOKUP()
与INDEX()
和CHOOSE()
或IF()
• 单元格H14
中使用的公式 --> 使用IF()
=INDEX(XLOOKUP($F$1,TableOne[#Headers], IF($E$1="TableOne",TableOne,TableTwo)),COLUMN(A1))
• 或者,单元格H19
中使用的公式 --> 使用CHOOSE()
=INDEX(XLOOKUP($F$1,TableOne[#Headers], CHOOSE(N($E$1<>"TableOne")+1,TableOne,TableTwo)),COLUMN(A1))
注意: 在上述所有公式中,我引用了结构化表,即TableOne和TableTwo。请根据您的需要调整范围。
英文:
In Excel
there are multitude of approaches to resolve a problem. Using Table Names with INDIRECT()
Function can also be accomplished, however using INDIRECT()
can be avoided as it is single-threaded and so defeats Excel’s
multi-threaded calculation engine. Still I am sharing the solution along with the other ways, you can try the one best suits with your query.
Approach One: --> Using INDIRECT()
& TOROW()
• Formula used in cell H4
--> It spills to right!
=TOROW(INDIRECT(E1&"["&F1&"]"))
• Or, Formula used in cell H9
--> Without #SPILL!
--> It needs to fill right!
=INDEX(INDIRECT($E$1&"["&$F$1&"]"),COLUMN(A1))
Approach Two: --> Using XLOOKUP()
with INDEX()
and CHOOSE()
or IF()
• Formula used in cell H14
--> Using IF()
=INDEX(XLOOKUP($F$1,TableOne[#Headers],
IF($E$1="TableOne",TableOne,TableTwo)),COLUMN(A1))
• Or, Formula used in cell H19
--> Using CHOOSE()
=INDEX(XLOOKUP($F$1,TableOne[#Headers],
CHOOSE(N($E$1<>"TableOne")+1,TableOne,TableTwo)),COLUMN(A1))
Note: In all of the above formulas I am referencing structured table viz. TableOne & TableTwo . Please adjust the ranges as per your suit.
答案3
得分: 0
我建议将这两个表格联接并稍微更改结构,这样您就可以避免使用 IF
语句(想象一下如果您需要使用更多表格),并使用类似以下的公式:
=SUM(($D$9:$E$9=D4)*($B$10:$B$15=C4)*($C$10:$C$15=E4)*($D$10:$E$15))
结果:
将这个“筛选后”的值用于您的进一步计算。
英文:
I would recommend to join those 2 tables and change structure a bit so you can avoid IF
statements (imagine if you need to use even more tables) and use something like this:
=SUM(($D$9:$E$9=D4)*($B$10:$B$15=C4)*($C$10:$C$15=E4)*($D$10:$E$15))
Result:
Use that "filtered" value for your further calculations.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论