从单列查询值和填充列,均基于多个条件

Query values from single column and fill columns, both based on multiple criteria

我正在尝试从源选项卡到输出选项卡仅查询满足特定条件的客户端 ID,并根据条件用静态值填充 2 列,用动态值填充 2 列。

在源选项卡中我有:

+-----------------------+------+
| Status                | ID   |
+-----------------------+------+
| Retired/Deceased      | 2a33 |
+-----------------------+------+
| Liquidation           | 1sTR |
+-----------------------+------+
| Dissolved             | 3B76 |
+-----------------------+------+
| Released from company | 463z |
+-----------------------+------+
| Active                | 557g |
+-----------------------+------+
| In progress           | zz34 |
+-----------------------+------+
| Demo                  | cc56 |
+-----------------------+------+

请注意,有 7 个标准值,我只需要其中 4 个的输出。这意味着我需要 4 个值,基于这些值将有动态列的二进制填充。其他 3 个值已过时。

从这 4 个值,如果我有例如。条件 1,那么我将填充 2 个动态列中的一个,如果没有(对于其他 3 个值)我将使用其他填充值。

所以我想简单地使用二进制解决方案来选择特定值是不适用的。

在输出选项卡逻辑中:

+--------------------------------------------------------------------------------+
|                                   Output tab                                   |
+--------------------------------------------------------------------------------+
| ID | Status | Reason | Comment                    | Detail                     |
+----+--------+--------+----------------------------+----------------------------+
| A1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| B1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| C1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null, else         |    then value 1,           |
|    |        |        |    criteria value          |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| D1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| E1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| F1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| G1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+

虚拟输出选项卡:

+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Status                | ID   | Status            | Reason      | Comment          | Detail                          |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Retired/Deceased      | 2a33 | Unable to proceed | Unspecified | Retired/Deceased | Retired/No longer in business   |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Liquidation           | 1sTR | Unable to proceed | Unspecified | Liquidation      | Retired/No longer in business   |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Dissolved             | 3B76 | Unable to proceed | Unspecified | Dissolved        | Retired/No longer in business   |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Released from company | 463z | Unable to proceed | Unspecified | (null)           | No longer works for the company |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+

'Status' 列不是必需的。我添加它只是为了参考和可读性。

抱歉,我有共享 Google 表格链接的公司安全限制。

我最纠结的部分是第 4 列(动态列中的第一个)需要 return 源选项卡中第 2 列的标准值。

到目前为止,我已经完成了查询的第一部分,其中我 QUERY 基于多个条件的 ID,标记并填充了静态值列。

=QUERY(Data!$A:$BN, 
    "SELECT B, 'Unable to proceed', 'Unspecified' 
     WHERE A = 'Retired/Deceased' 
      OR A = ''Liquidation' 
      OR A = 'Dissolved'  
      OR A = 'Released from company' 
      AND A IS NOT NULL
     LABEL 'Unable to proceed' 'Unspecified' , 'Status' 'Reason'", 1)

但是,基于多个标准,我正在努力处理动态列。

我在嵌套 QUERY 中用 IFERRORVLOOKUP 查找了 ARRAYFORMULA,但无法解决它。

此外,如果有超过 2 个值选项来填充输出选项卡中的第 3 列和第 4 列,我对这将如何工作非常感兴趣。 据我所知,基于条件解决 2 个值的方法是嵌套一个 IFERROR 函数以使其成为二进制。但是,如果要填充数组的值超过 2 个怎么办?

基于 ID:

=QUERY({QUERY(Data!$A:$B, 
        "SELECT B, 'Unable to proceed', 'Unspecified' 
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL
         LABEL 'Unable to proceed''Status', 'Unspecified''Reason'", 1),
        QUERY(ARRAYFORMULA(IFERROR(VLOOKUP(
        QUERY(Data!$A:$B, 
        "SELECT B
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL", 0), 
 {"2a33", "Retired/Deceased", "Retired/No longer in business";
  "1sTR", "Liquidation",      "Retired/No longer in business";
  "3B76", "Dissolved",        "Retired/No longer in business";
  "463z", "",                 "No longer works for the company"}, {2, 3}, 0), )), 
        "LABEL Col1'Comment', Col2'Detail'", 0)}, , 0)

基于状态:

=QUERY({QUERY(Data!$A:$B, 
        "SELECT B, 'Unable to proceed', 'Unspecified' 
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL
         LABEL 'Unable to proceed''Status', 'Unspecified''Reason'", 1),
        QUERY(ARRAYFORMULA(IFERROR(VLOOKUP(
        QUERY(Data!$A:$B, 
        "SELECT A
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL", 0), 
 {"Retired/Deceased",      "Retired/Deceased", "Retired/No longer in business";
  "Liquidation",           "Liquidation",      "Retired/No longer in business";
  "Dissolved",             "Dissolved",        "Retired/No longer in business";
  "Released from company", "",                 "No longer works for the company"}, {2, 3}, 0), )), 
        "LABEL Col1 'Comment', Col2 'Detail'", 0)}, , 0)