简体   繁体   中英

How to use ArrayFormula in Google Sheets, with multiple IF conditions?

So I just found out about ArrayFormula and am trying to convert my spreadsheet to utilize it, to be more efficient. Its worked wonderfully on all my columns except one, which is giving me trouble.

=IF(C2="Immediate",
  D2+1,
  IF(C2="3 Day",
    WORKDAY(D2,3,Holidays!$B$2:$B$11),
    IF(C2="5 Day",
      WORKDAY(D2,5,Holidays!$B$2:$B$11),
      IF(ISBLANK(C2),
        IFERROR(1/0)
      )
    )
  )
)

I know this is old but maybe try this formula:

={"Header_Cell_Name_Here";
  ArrayFormula(
    IFS(
      $C$2:$C="","",
      $C$2:$C="Immediate", $D$2:$D + 1,
      $C$2:$C="3 Day", WORKDAY($D$2:$D,3,Holidays!$B$2:$B$11),
      $C$2:$C="5 Day", WORKDAY($D$2:$D,5,Holidays!$B$2:$B$11)
    )
  )
}

IFS is a great alternative to IF. Rather than taking three arguments like you do with an IF statement:

IF(logical_expression, value_if_true, value_if_false)

an IFS statement can handle any number of conditions:

IFS(condition1, value1, [condition2, ...], [value2, ...])

在工作表第 1 行的某处试试这个公式:

=ARRAYFORMULA(IF(A:A="",,IF(A:A=1,"Hello",IF(A:A=2,"Goodbye","Other Result"))))

you can use that formula

=ArrayFormula(IF(C2:C="",IFERROR(1/0),IF(C2:C="Immediate",D2:D+1,IF(C2:C="3 Day",WORKDAY(D2:D,3,Holidays!$B$2:$B$11),IF(C2:C="5 Day",WORKDAY(D2:D,5,Holidays!$B$2:$B$11),IF(ISBLANK(C2:C),IFERROR(1/0)))))))

here is an example

Your first formula, expanded to arrays, works perfectly well for me

=ARRAYFORMULA(IF(C2:C5="Immediate",
                 D2:D5+1,
                 IF(C2:C5="3 Day",
                    WORKDAY(D2:D5,3,Sheet2!$B$2:$B$11),
                    IF(C2:C5="5 Day",
                       WORKDAY(D2:D5,5,Sheet2!$B$2:$B$11),
                       IF(ISBLANK(C2:C5),
                          IFERROR(1/0)
                       )
                    )
                 )
              )
 )

This is the best arrayformula with multi if conditions<\/strong> I usually use

=Arrayformula(if(isblank(A2:A),,if((condition1) * (condition2) * (condition3),statement, if((condition1) * (condition2) * (condition3), statement, ))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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