简体   繁体   English

如果单元格包含特定文本,则返回记分表的值和总和行

[英]If Cell Contains Specific Text Then Return Value and Sum Row for Scoresheet

I am trying to create a formula that takes a selection of choices from a cell and turns it into a "score", then at the end of the row it adds the score up.我正在尝试创建一个公式,该公式从单元格中选择一个选项并将其转换为“分数”,然后在行的末尾将分数相加。 I know this is not correct but it would be along the lines of我知道这是不正确的,但它会沿着

=(IF(A2="Red", 1, "")), (IF(A2="Blue", 2, "")), ,(IF(A2="Green", 3, "")), (IF(A2="Yellow", 4, "")), (IF(A3="Oval", 1, "")), (IF(A3="Octagon", 2, "")), (IF(A3="Triangle", 3, "")), (IF(A3="Square", 4, ""))...

and then at the end SUM A2:D2.然后在最后 SUM A2:D2。

Can anyone help me with this?谁能帮我这个? Thank you!谢谢!

在此处输入图像描述

Here is an explanation to the formula which I have posted above in comments with few other alternatives, which you may give a try, if you are using O365这是我在上面的评论中发布的公式的解释以及其他一些替代方案,如果您使用的是O365 ,您可以尝试一下

FORMULA_解决方案

• Formula used in cell E2 • 单元格E2中使用的公式

=SUM(LOOKUP(A2,{"Blue","Green","Red","Yellow"},{2,3,1,4}),
LOOKUP(B2,{"Octagon","Oval","Square","Triangle"},{2,1,4,3}),
LOOKUP(C2,{"Bank","Church","Playground","School"},{3,1,4,2}),
LOOKUP(D2,{"Bank Teller","Doctor","Martial Arts Instructor","Teacher"},{4,1,3,2}))

So how does LOOKUP() Function works?那么 LOOKUP() 函数是如何工作的呢?

  • The LOOKUP() function looksup a value in a one-column or one-row range, and retrieve the value from the same position in another one-column or one-row range. LOOKUP()函数在一列或一行范围内查找一个值,并从另一个一列或一行范围内的相同位置检索该值。
  • The LOOKUP() function has two forms, one is vector and another is array . LOOKUP()函数有两种形式,一种是向量,另一种是数组
  • The LOOKUP() function accepts three arguments: lookup_value , lookup_vector , and result_vector . LOOKUP()函数接受三个参数: lookup_valuelookup_vectorresult_vector
  • The first argument is lookup_value which is the value to look for.第一个参数是lookup_value ,它是要查找的值。
  • The second argument is lookup_vector which is a one-row, or one-column range to search.第二个参数是lookup_vector ,它是要搜索的单行或单列范围。
  • While the third argument which is result_vector , is a one-row, or one-column range of results.而第三个参数result_vector是单行或一列的结果范围。
  • Result_vector is optional.结果向量是可选的。 When result_vector is provided, LOOKUP() Function locates a match in the lookup_vector , and returns the corresponding value from result_vector .当提供了result_vector时, LOOKUP()函数在lookup_vector中定位匹配,并从result_vector返回对应的值。
  • If result_vector is not provided, LOOKUP() function returns the value of the match found in lookup_vector .如果未提供result_vector ,则LOOKUP()函数将返回在lookup_vector中找到的匹配值。
  • LOOKUP() Function assumes that lookup_vector is sorted in ascending order . LOOKUP()函数假定lookup_vector升序排序的。
  • LOOKUP() Function is not case-sensitive . LOOKUP()函数不区分大小写

However I assume you have access to O365 then you may try using the [XLOOKUP()][2] Function as well, XLOOKUP() is a much faster function than anyother lookup function但是我假设您可以访问O365 ,那么您也可以尝试使用[XLOOKUP()][2]函数, XLOOKUP()是一个比任何其他查找函数快得多的函数

• Formula used in cell G2 • 单元格G2中使用的公式

=SUM(XLOOKUP(A2,{"Blue","Green","Red","Yellow"},{2,3,1,4}),
XLOOKUP(B2,{"Octagon","Oval","Square","Triangle"},{2,1,4,3}),
XLOOKUP(C2,{"Bank","Church","Playground","School"},{3,1,4,2}),
XLOOKUP(D2,{"Bank Teller","Doctor","Martial Arts Instructor","Teacher"},{4,1,3,2}))

One more way is to use LAMBDA() Function, to create a custom , reusable function and refer them by a friendly name ,另一种方法是使用LAMBDA()函数,创建自定义的、可重用的函数并通过友好名称引用它们,

• Formula used in cell F2 • 单元格F2中使用的公式

=SumScores(A2,B2,C2,D2)

Where,在哪里,

SumScores => 

=LAMBDA(a,b,c,d,
SUM(XLOOKUP(a,{"Blue","Green","Red","Yellow"},{2,3,1,4}),
 XLOOKUP(b,{"Octagon","Oval","Square","Triangle"},{2,1,4,3}),
 XLOOKUP(c,{"Bank","Church","Playground","School"},{3,1,4,2}),
 XLOOKUP(d,{"Bank Teller","Doctor","Martial Arts Instructor","Teacher"},{4,1,3,2})))

LAMBDA() Function used in Name Manager with a Defined Name as SumScores with syntax as LAMBDA()函数在名称管理器中使用,定义名称SumScores ,语法为

=SumScores(a,b,c,d)

EDIT编辑

OP mentioned in comments : So XLOOKUP() works perfectly, however, I just found out I am using Slack for my integration and can only use Google Sheet - nooooooo!!! OP 在评论中提到:所以XLOOKUP()完美运行,但是,我刚刚发现我正在使用 Slack 进行集成,并且只能使用 Google Sheet - nooooooo!!!

FORMULA_SOLUTION_GS

• Formula used in cell E2 • 单元格E2中使用的公式

=ARRAYFORMULA(SUM(VLOOKUP(A2,{"Blue",2;"Green",3;"Red",1;"Yellow",4},2,0),
VLOOKUP(B2,{"Octagon",2;"Oval",1;"Square",4;"Triangle",3},2,0),
VLOOKUP(C2,{"Bank",3;"Church",1;"Playground",4;"School",2},2,0),
VLOOKUP(D2,{"Bank Teller",4;"Doctor",1;"Martial Arts Instructor",3;"Teacher",2},2,0)))

Here is a formula solution based on the OP's layout.这是基于 OP 布局的公式解决方案。

In E2 , array ("Ctrl"+"Shift"+"Enter") formula copied down :E2中,数组 ("Ctrl"+"Shift"+"Enter") 公式向下复制:

=SUM(FILTERXML("<a "&SUBSTITUTE(TEXTJOIN("' ",,SUBSTITUTE(A$9:D$12," ","_")),"=","='")&"'/>","//@"&SUBSTITUTE(A2," ","_")&"|//@"&B2&"|//@"&C2&"|//@"&SUBSTITUTE(D2," ","_")))

在此处输入图像描述

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

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