简体   繁体   English

基于 VLookup 的动态数据验证列表

[英]Dynamic Data Validation lists based on VLookup

I'm trying to add a custom 'discount' list to my spreadsheet.我正在尝试将自定义“折扣”列表添加到我的电子表格中。

I've got a table that contains all the data, and has costs for the standard 'used' value, then also the values at a 5% discount and a 10% discount.我有一个包含所有数据的表格,包含标准“已用”价值的成本,还有 5% 折扣和 10% 折扣的价值。

Example:例子:

+---------+-------------------+------+------------+-------------+
|  Code   |       Role        | Used | Used - 5%  | Used - 10%  |
+=========+===================+======+============+=============+
| Test001 |     Employee      | 5.67 |            |             |
+---------+-------------------+------+------------+-------------+
| Test002 | Junior Technician | 9.80 |    9.31    |    8.38     |
+---------+-------------------+------+------------+-------------+
| Test003 |  Project Manager  |  15  |            |             |
+---------+-------------------+------+------------+-------------+
| Test004 |     Engineer      |  20  |     19     |    17.10    |
+---------+-------------------+------+------------+-------------+

I've then got a Data validation list which returns all other the 'Roles' to select from.然后我有一个数据验证列表,它将所有其他“角色”返回到 select。 On the back of this this populates the Cost cell.在这背后填充成本单元格。

Example:例子:

+----------+----------+----------+-------+
|   Role   | VLOOKUP  | Discount | Cost  |
+==========+==========+==========+=======+
| Employee |          |          | 5.67  |
+----------+----------+----------+-------+
| Engineer |  5%,10%  |   10%    | 15.10 |
+----------+----------+----------+-------+

What I want to do is have a list to be populated with 5%, 10% if there is that option.我想要做的是有一个列表,其中包含 5%、10%(如果有该选项)。 I'd like to achieve this without vba (I could easily achieve this with vba but trying to keep it all in the worksheet)我想在没有 vba 的情况下实现这一目标(我可以使用 vba 轻松实现这一目标,但试图将其全部保留在工作表中)

My VLOOKUP Column is populated using:我的VLOOKUP列使用以下方法填充:

=CONCATENATE(IF(VLOOKUP(A2,INDIRECT("Test[[Role]:[Used - 10%]]"), 3, FALSE) <> "", "5%", ""), 
IF(VLOOKUP(A2,INDIRECT("Test[[Role]:[Used - 10%]]"), 4, FALSE) <> "", ",10%", ""))

The issue comes when trying to do the data validation.尝试进行数据验证时会出现问题。 It accepts the formula (tried using the above to no avail in the data validation) but populates the drop down list with just the one value of 5%,10% instead of interpreting it as a csv.它接受公式(尝试使用上述公式在数据验证中无济于事)但仅使用5%,10%的一个值填充下拉列表,而不是将其解释为 csv。

I'm currently using this to attempt to populate the Discount Drop Down我目前正在使用它来尝试填充折扣下拉菜单

=OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),0, -1)

It is possible assuming your version of Excel has access to the dynamic functions FILTER and UNIQUE.假设您的 Excel 版本可以访问动态函数 FILTER 和 UNIQUE,这是可能的。 Let's go through a couple of things, and here is a google doc where this is demonstrated.让我们 go 通过一些事情,这里是一个谷歌文档,其中对此进行了演示。 I also included an online excel file *.我还包括一个在线excel 文件*.

  1. It isn't necessary to calculate the cost in the setup table (A:E).无需在设置表 (A:E) 中计算成本。 You can just use a character to mark availability (and in some versions it was difficult to make the FILTER work with comparisons like <>"", etc, when ="x" worked fine).您可以只使用一个字符来标记可用性(在某些版本中,当 ="x" 工作正常时,很难使 FILTER 与 <>"" 等比较一起工作)。

  2. You can get an array of available discounts by using FILTER, INDEX and MATCH.您可以使用 FILTER、INDEX 和 MATCH 获得一系列可用折扣。 See Col P. You use INDEX/MATCH to return a single row of the array containing the discounts (in this case D:E), and then use that row to filter the top row (D1:E1) which has the friendly discount names and return it as an array.请参见 Col P。您使用 INDEX/MATCH 返回包含折扣的数组的单行(在本例中为 D:E),然后使用该行过滤具有友好折扣名称的第一行 (D1:E1)并将其作为数组返回。

  3. It isn't necessary to concat the discount list the way you're doing.没有必要按照您的方式连接折扣列表。 You can use TEXTJOIN, FILTER, INDEX and MATCH.您可以使用 TEXTJOIN、FILTER、INDEX 和 MATCH。 See Col I. You just wrap the calculation that generates the array of discount names (step 2) in TEXTJOIN to get a string.请参阅第 I 列。您只需将生成折扣名称数组(第 2 步)的计算包装在 TEXTJOIN 中以获取字符串。

  4. The validation is accomplished by referencing the output of step 2. I don't think that the data validation dialog can handle the full formula, so I pointed it to Cols O:Q.验证是通过引用步骤 2 的 output 完成的。我不认为数据验证对话框可以处理完整的公式,所以我将其指向 Cols O:Q。 Col O is included in the validation so that you can get an empty spot at the top of the list, but Google Docs seems to strip it out. Col O 包含在验证中,因此您可以在列表顶部得到一个空白点,但 Google Docs 似乎将其删除。

  5. You can just calculate the discounted cost from the selected option.您可以只计算所选选项的折扣成本。 See Col K. I included the original cost in Col L so you can see it.请参见 Col K。我将原始成本包含在 Col L 中,因此您可以看到它。

  • you will need a microsoft account to view您将需要一个 Microsoft 帐户才能查看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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