簡體   English   中英

Google 表格中的 IFS 公式

[英]IFS Formula in Google Sheets

我正在谷歌表格中尋找一個公式。

該公式基於“輸入”表和“輸出”表。 在“輸入”表中有以下列:

current_position, company_name, current_position_2, current_company_2

在“輸出”表中有“標題”和“帳戶名稱”輸入+ Output

公式應該在“輸出”中的“標題”中並說:

1)

如果“current_position”包含“COO”、“CEO”、“CSO”(以及更多頭銜),則取“company_name”並在“Output”下輸入“Account Name”。

2)

如果“current_position”不包含“COO”、“CEO”、“CSO”(以及更多頭銜)並且“current_position_2”包含“COO”、“CEO”、“CSO”(以及更多頭銜),則輸入“Output”中“Title”中的“current_position_2”和“Output”中“Account Name”中的“current_company_2”

3)

如果“current_position”或“current_position_2”都不包含“COO”、“CEO”、“CSO”(以及更多頭銜),則取“current_position”並在“Output”和“Current_position_2”下輸入“Title”並輸入“輸出”中的“帳戶名稱”

筆記:

盡可能確保包括您迄今為止所做的工作或分享您所做的任何研究,以確保您發布了一個好的問題

推薦:

在我的測試中,IFS Function 非常有限,無法實現根據多個條件為不同列設置值的目標。

我通過創建自定義 function提出了另一種解決方案,該解決方案檢查“輸入”表上的所有值並根據您上面描述的 3 個條件返回“輸出”表上的值:

更新腳本:

function onOpen() { // to refresh 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Output').getRange('C2').setValue("=checkImput()");
}

function checkImput(){
  var imput = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Imput');
  var row = imput.getDataRange().getNumRows();
  var res = [];

  for(var x=2; x<=row; x++){
    var current_position = imput.getRange(x,7).getValue();
    var current_position2 = imput.getRange(x,43).getValue();
    var positions = "COO,CEO,CSO"; //Add new postion separated by comma

    if(positions.includes(current_position)){ // If "courrent_position" contains "COO", "CEO", "CSO" 
      res.push([current_position,imput.getRange(x,8).getValue()]); //Then put "current_position" in "Title" and "current_company" in Account Name
    }else{
      if(positions.includes(current_position2)){ //If "current_position" does not contain "COO", "CEO", "CSO" (and a lot more titles) AND "current_position_2" contain "COO", "CEO", "CSO" 
        res.push([current_position2,imput.getRange(x,44).getValue()]); //Then put "current_position_2" in "Title" in "Output" and "current_company_2" in "Account Name" in "Output"
      }else{ //If neither of "current_position" or "current_position_2 contains "COO", "CEO", "CSO" (and a lot more titles) 
        res.push([current_position2,imput.getRange(x,44).getValue()]); //Then take "current_position" and put in "Title" under "Output" and "Current_position_2" and put in "Account Name" in "Output"
      }
    }
  }
 return res;
}

這是我測試過的示例“輸入”表:

在此處輸入圖像描述

“輸出”表上的結果

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM