Search code examples
arraysif-statementgoogle-sheetsgoogle-sheets-formulaarray-formulas

Google Sheets IF function to return value


I have this table of ID in Google Sheets :

All_ID       product_id     Package ID  subpackage ID
                              65385A    65385A1
                                        65385A2
             65385            65385B    65385B1
                                        65385B2
             52002            52002A    
                              52002B    52002B1
                                        52002B2
                              52002C    
                              52002D

             60000  

How do I return in ALL_ID column the most 'detailed' ID in Google Sheets Or in (excel equivalent)?

 All_ID      product_id        Package ID  subpackage ID
 65385A1                          65385A    65385A1
 65385A2                                    65385A2
 65385B1         65385            65385B    65385B1
 65385B2                                    65385B2
  52002A         52002            52002A    
 52002B1                          52002B    52002B1
 52002B2                                    52002B2
  52002C                          52002C    
  52002D                          52002D
  60000          60000  

I was using some function like this for two columns (=IF(B1="",C1,B1)


Solution

  • use in row 2:

    =ARRAYFORMULA(IF(D2:D<>"", D2:D, 
                  IF(C2:C<>"", C2:C, 
                  IF(B2:B<>"", B2:B, ))))