简体   繁体   English

如何在 Google 表格中整齐地从多个 IF 结果创建结果

[英]How to create result from multiple IF results neatly in Google Sheets

I want to combine multiple results of if statement into a form of a sentence.我想将if语句的多个结果组合成一个句子的形式。

Code:代码:

=CONCAT("Fail column", IF($T3="No", " T", "")& IF($U3="No", ", U", "") & IF($W3<7, ", W", "") & IF($X3>3, ", X", "") & IF($AE3="No", ", AE", "") & IF($AF3="No", ", AF", ""))

Sample data :样本数据 : 在此处输入图片说明

If the first statement returns blank, the next statement would not show the comma at the beginning.如果第一条语句返回空白,则下一条语句不会在开头显示逗号。 And let say all pass, they would be shown as "Yes".假设全部通过,它们将显示为“是”。

My expected output can be:我的预期输出可以是:

  1. Fail column T, U, W, X, AE, AF失败列 T、U、W、X、AE、AF
  2. Fail column U, W, X, AE, AF失败列 U、W、X、AE、AF
  3. Fail column T失败列 T
  4. Fail column W, X失败列 W, X
  5. Yes是的

I'm thinking you could try:我想你可以尝试:

在此处输入图片说明

Formula in R3 : R3公式:

=IF(OR(T3="No",U3="No",W3<7,X3>3,AE3="No",AF3="No"),"Fail column: "&TEXTJOIN(", ",TRUE,IF(T3="No","T",""),IF(U3="No","U",""),IF(W3<7,"W",""),IF(X3>3,"X",""),IF(AE3="No","AE",""),IF(AF3="No","AF","")),"Yes")

The key here is TEXTJOIN instead of CONCAT to exclude any empty values from the concatenated string.这里的关键是TEXTJOIN而不是CONCAT从连接的字符串中排除任何空值。

Note: Excel and Google Spreadsheets are two different apps and the functions are not always exchangeable.注意: Excel 和 Google 电子表格是两个不同的应用程序,它们的功能并不总是可以互换的。 Your question's title suggests that you are actually using Excel, however your tags include GS.您的问题标题表明您实际上使用的是 Excel,但是您的标签包含 GS。

correct formula would be:正确的公式是:

=ARRAYFORMULA(REGEXREPLACE(IF(
 (T3:T="yes")*(U3:U="yes")*((W3:W<7)*(W3:W<>""))*(X3:X>3)*(AE3:AE="yes")*(AF3:AF="yes"), 
 "yes", "Fail column: "&
 IF(T3:T="no",            "T, ", )&
 IF(U3:U="no",            "U, ", )&
 iF(W3:W>=7,              "W, ", )&
 IF((X3:X<=3)*(X3:X<>""), "X, ", )&
 IF(AE3:AE="no",          "AE, ", )&
 IF(AF3:AF="no",          "AF, ", )), ", $|Fail column: $", ))

0

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

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