【问题标题】:Query values from single column and fill columns, both based on multiple criteria从单列和填充列中查询值,均基于多个条件
【发布时间】:2023-03-26 10:20:01
【问题描述】:

我正在尝试仅查询满足从源选项卡到输出选项卡的特定条件的客户端的 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 |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+

“状态”列不是必需的。我添加它只是为了参考和阅读。

抱歉,我在共享 Google 表格链接方面存在公司安全限制。

我最纠结的部分是第 4 列(动态列中的第一个)需要从源选项卡的第 2 列返回条件值。

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

=QUERY(Data!$A$3:$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 个呢?

【问题讨论】:

    标签: google-sheets google-sheets-formula google-sheets-query


    【解决方案1】:

    基于状态:

    =QUERY({QUERY(Data!$A$1:$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$2:$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)
    

    【讨论】:

      【解决方案2】:

      基于 ID:

      =QUERY({QUERY(Data!$A$1:$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$2:$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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-11
        • 2020-11-17
        • 2020-01-06
        • 1970-01-01
        • 2022-01-07
        • 1970-01-01
        • 2017-09-02
        • 1970-01-01
        相关资源
        最近更新 更多