Google Sheets – 数据验证 – 基于另一工作表中的列的条件

huangapple go评论88阅读模式
英文:

Google Sheets - Data Validation - Conditional based on Column in another sheet

问题

我目前正在为一个美食节设计菜单。我使用Google表格。我有一张填满食物选择的表格。给定周的菜单不应包含上周的食物项目。这是一个强制要求,如果我使用数据验证和自定义公式,我就无法获得下拉菜单。

我使用=FILTER('Item Suggestions'!A:A,'Item Suggestions'!E:E="Y")作为验证数据的自定义公式。

是否有其他方法(或调整以获得数据验证下拉菜单)来获取下拉菜单并保持下拉菜单列表被筛选?

“Menu”表的每一列都应该从“Item Suggestions”表的A列中选择。但数据应该基于E列。如果E列为Y,那么该列A中的数据应该显示在下拉菜单中。

菜单表:

第A列 第B列 第C列 第D列 第E列
开胃菜 主菜 第二道 甜点 饮料
鸡肉 奶油面条 草莓慕斯 火与冰
西兰花 米饭和咖喱 烤饼和蔬菜 冰淇淋圣代 莫吉托

“Item Suggestions”表:

第A列 第B列 第C列 第D列 第E列
菜肴 课程 过敏原 类型 用于上周?
奶油面条 主菜 麸质 素食 Y
巧克力大理石蛋糕 甜点 小麦 素食 N
英文:

Im currently designing a menu for a food festival. I use google sheets. I have a sheet filled with food choices. the menu for a given week should not have food items from the previous weeks. This is a mandatory requirement & I'm not able to get the drop-down if I use Data validation & custom formula.

I use =FILTER('Item Suggestions'!A:A,'Item Suggestions'!E:E="Y") as the custom formula for validating the data.

Is there any other way (or a tweak to get the data validation drop down) to get the drop-down & keep the drop-down list filtered?

Each of the columns in the "Menu" sheet should pick from column A of the "Item Suggestions" sheet. But the data should be based on column E. If Column E is Y, then that respective data in Column A should be shown in the drop-down

Menu Sheet:

Column A Column B Column C Column D Column E
Appetizers Mains Course 2 Dessert Drinks
Soup Chicken Creamy Pasta Strawberry Mousse Fire and Ice
Broccoli Rice & Curry Roti & Subzi Icecream Sundae Mojito

Item Suggestions sheet:

Column A Column B Column C Column D Column E
Dish Course Allergens Type Used in Previous weeks?
Creamy Pasta Main Gluten Vegetarian Y
Chocolate Marble Cake Dessert Wheat Vegan N

答案1

得分: 1

验证助手列

我为验证添加了一些“助手”列。

  1. 它们可以在同一个工作表上或不同的工作表上。
  2. 每门课程都有一个:Appetizer(开胃菜)、Main(主菜)、Dessert(甜点)和Drink(饮料)。我假设Main(主菜)和Course 2(第二道菜)都使用相同的菜品。
  3. FILTER公式会返回一个与正确的“课程”匹配且尚未使用的“菜品”数组:
=IFERROR(FILTER(Dishes, Courses=thisCourse, isUsed<>"Y"), "-")
  1. 对于验证规则,
    • 标准将是“下拉菜单(来自范围)”,范围将是每个“课程”的适当助手列。
    • “应用于范围”值将是您的“菜单”表中适当的“课程”列。
  2. 请注意,所有填充的菜单项将始终显示错误标志(位于右上角的红色三角形)。这是因为一旦它们被使用,它们就不再是有效值。这不会影响菜单下拉列表的功能。已使用的菜单项将从下拉列表中过滤掉,您将无法使用下拉属性设置为拒绝的方式手动添加已使用的菜单项。这只是一种视觉干扰。

下拉菜单公式

单一公式

将同时生成所有下拉列表并集中修改

=BYCOL(M2:P2, LAMBDA(c, 
   IFERROR(FILTER(G:G, H:H=c, K:K<>"Y"), "-")))
单独公式

需要手动复制到每个列中

=IFERROR(FILTER($G:$G, $H:$H=M2, $K:$K<>"Y"), "-")

筛选公式
Google Sheets – 数据验证 – 基于另一工作表中的列的条件

带有筛选后的菜品的下拉列表
Google Sheets – 数据验证 – 基于另一工作表中的列的条件

用于标记已使用菜品的公式

  1. 您的“菜品大全”包括一个列来标记菜品是否先前已使用。
  2. 您的菜单的下拉列表基于此,并且在菜品被添加或从菜单中删除时动态更新“已使用/未使用”状态是合理的。
  3. 这可以通过在“菜品大全”中使用公式来实现,该公式根据菜品是否存在于菜单中来标记每道菜品。

菜品“已使用”公式

请注意,“单一公式”包括列标题“已在先前几周中使用?”。

  • 这是有意为之的,以便将公式放在“菜品大全”数据的上方一行。
  • 通过将公式与数据相隔一行,可以在不影响公式的情况下对数据进行排序。例如,您可以按“菜品”、“课程”、“过敏原”或“类型”对“菜品大全”进行排序。
单一公式
={"已在先前几周中使用?";
  BYROW(G3:G51, LAMBDA(r, 
    IFERROR(IF(ROWS(FILTER(r, COUNTIF(A:E, r)))>0, "Y", ""))))}
单独公式

需要复制到每一行

=IFERROR(IF(ROWS(FILTER(G3, COUNTIF(A:E, G3)))>0, "Y", ""))

按菜品升序排序
Google Sheets – 数据验证 – 基于另一工作表中的列的条件

按课程然后按菜品升序排序
Google Sheets – 数据验证 – 基于另一工作表中的列的条件

英文:

Validation Helper Columns

I added some 'helper' columns for the validation.

  1. They can be on the same sheet or a different one.
  2. There is one for each course: Appetizer, Main, Dessert, and Drink. I assume Main and Course 2 both share the same dishes.
  3. The FILTER formula would return an array of Dishes that match the correct Course, and haven't yet been used:
=IFERROR(FILTER(Dishes,Courses=thisCourse,isUsed&lt;&gt;&quot;Y&quot;),&quot;-&quot;)
  1. For the validation rule,
    • the criteria would be &quot;Dropdown (from a range)&quot; with the range being the appropriate helper column for each Course
    • The &quot;Apply to range&quot; value would be the appropriate Course column in your Menu table
  2. Please note that all populated menu items will 'always' show the error flag (red triangle in the top right corner). This is because the moment they are used, they are no longer valid values. This doesn't affect the functionality of the menu dropdowns. Used menu items will be filtered from the dropdowns, and you will not be able to add a used menu item manually with the dropdown properties set to reject. Just a visual distraction.
Single Formula

Will generate all dropdowns at once and centralizes modifications

=BYCOL(M2:P2, LAMBDA(c, 
   IFERROR(FILTER(G:G,H:H=c,K:K&lt;&gt;&quot;Y&quot;),&quot;-&quot;)))
Individual Formula

Needs to be manually copied to each column

=IFERROR(FILTER($G:$G,$H:$H=M2,$K:$K&lt;&gt;&quot;Y&quot;),&quot;-&quot;)

<sub>Filtering Formula</sub><br>
[<img src="https://i.stack.imgur.com/YzgOC.png" width="550" />](https://i.stack.imgur.com/YzgOC.png "click to enlarge")

<sub>Dropdown with Filtered Dishes</sub><br>
[<img src="https://i.stack.imgur.com/4AJM1.png" width="550" />](https://i.stack.imgur.com/4AJM1.png "click to enlarge")

Formula to Mark Dishes When Used

  1. Your Master List of dishes includes a column to mark if a dish has been used previously
  2. Your menu's dropdowns are based on that and it makes sense to update the "used/not used" status dynamically when a dish is added or removed from a menu.
  3. This can be achieved using a formula in the Master List that marks each dish based on whether it exists in the menu.

Dish "Is Used" Formula

Note that the 'Single Formula' includes the column heading &quot;Used in previous weeks?&quot;.

  • This was intentional in order to place the formula a line above the Master List data
  • Offsetting the formula from the data by a row, allows the data to be sorted without impacting the formula. For example, you could sort the Master List by any of Dishes, Courses, Allergens, or Type
Single Formula
={&quot;Used in previous weeks?&quot;;
  BYROW(G3:G51, LAMBDA(r, 
    IFERROR(IF(ROWS(FILTER(r,COUNTIF(A:E,r)))&gt;0,&quot;Y&quot;))))}
Individual Formulas

Needs to be copied to each row

=IFERROR(IF(ROWS(FILTER(G3,COUNTIF(A:E,G3)))&gt;0,&quot;Y&quot;))

<sub>Sorted Asc. by Dishes</sub><br>
[<img src="https://i.stack.imgur.com/vcxEI.png" width="550" />](https://i.stack.imgur.com/vcxEI.png "click to enlarge")<br><br>

<sub>Sorted Asc. by Courses then Dishes</sub><br>
[<img src="https://i.stack.imgur.com/Kp8bq.png" width="550" />](https://i.stack.imgur.com/Kp8bq.png "click to enlarge")<br><br>

huangapple
  • 本文由 发表于 2023年6月1日 21:33:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76382443.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定