Analisi dei Dati e Reporting nel Marketing
Strategie e Tendenze del Marketing Digitale

La Formula Definitiva di Google Sheets Per Unire Tabelle

Ever wondered which formula you can use to join tables in Google Sheets? And automatically? The kind of magic formula that would be easy to reuse and does exactly what you need. If you want to know how, then read on.

Every user finds it extremely important to find an efficient Google Sheets formula that can work wonders for their data. However, it has been a challenge to get such effective formulas because chaining multiple functions can quickly create complex queries.

While many formulas are at our disposal, most require some creativity to make them ideal for your situations. So, when it comes to joining two or more tables, we have to depend on some other functions and reference knowledge to create a Google Sheets formula that can do the job effectively.

Se hai trovato il processo di unione delle tabelle noioso o complicato, questo articolo ti aiuterà a capire tutto ciò che devi sapere. Quindi, tuffiamoci subito in questa formula di Google Sheet per unire le tue tabelle!

What Google Sheets formula do you need to join tables?

Come abbiamo detto, unire due tabelle implica combinare diverse funzioni. La formula che costruiremo include due potenti funzioni di Google Sheets per unire le nostre tabelle: la FILTER e la VLOOKUP.

As you can see, the functions are not new, but when combined with a few other tricks, they can revolutionize how you process your most complex data. Before we dive into the formula, we need to solidify our understanding of these functions of the query before we can create it.

So, let’s roll up our sleeves and get down to business.

La funzione FILTER

Google Sheet formula FILTER is a powerful slice and dice function. The syntax for this function is:

Dove:

  • L'intervallo è l'intervallo di celle che desideri filtrare.
  • Condizione1 is the row or column that corresponds to the dataset and returns an array with Boolean values: the TRUE or FALSE values based on your conditions.
  • Condizione2: While this is an optional argument, it serves the same function as condition 1, helping you chain conditions. 

La funzione FILTER restituisce la versione filtrata del tuo intervallo. Restituisce solo le righe o colonne che soddisfano le condizioni specificate che fornisci. 

Quindi, se questa funzione può restituire una riga o una colonna in base alle nostre condizioni, sarà una delle nostre funzioni utili.

La funzione VLOOKUP

Quando vuoi fare riferimento a dati provenienti da fogli o tabelle diversi in Google Sheets, il VLOOKUP viene in aiuto. Questa funzione di ricerca verticale è potente e può lavorare con dati provenienti da fogli esterni, rendendola potente e perfetta per il nostro scopo.

You can use the Google Sheets formula VLOOKUP to source or lookup values that match another table, so here’s the syntax:

Dove:

  • La chiave di ricerca: Il parametro search_key sono i valori che vogliamo cercare. Puoi inserire i dati, come 'Texas', 3400 o A12. Qui, puoi combinare valori provenienti da diverse colonne per ottenere una colonna di ricerca unica.
  • L'intervallo: The second parameter in the VLOOKUP Google Sheets formula is the range: the references to cells where you want to search your data. 
  • L'indice: Un altro parametro nella funzione VLOOKUP è l'indice. L'indice è la posizione della colonna che desideri ottenere. Il numero della colonna inizia sempre dalla prima cella del tuo intervallo di ricerca, partendo da 1 e non da 0.
  • Il parametro is_sorted: The final parameter in a VLOOKUP function is the is_sorted. This parameter shows whether we should sort the first column in ascending order or not. So, its values can either be FALSE or TRUE. When set to FALSE, the search range will not be sorted and remains in the original order.

Illustrazione di VLOOKUP

To illustrate how to join a table using the Google Sheets formula VLOOKUP, we will use the following tables for our example. Here, we have two tables that share a common key, the Nome.

AB
1NomeDipartimento
2EricVendite
3JaneIT
4JohnControllo Qualità
Tabella A su FoglioA
AB
1NomeStipendio
2Eric$45500
3Jane$31850
4John$21440
Tabella B su FoglioB

If we need a Google Sheets formula to join the two tables above, here’s how we will achieve the results in Sheet C below:

ABC
1NomeDipartimentoStipendio
2EricVendite$45500
3JaneIT$31850
4JohnControllo Qualità$21440
SheetC

Tabella A elenca i Nomi e Dipartimenti dei dipendenti. La seconda tabella elenca i Nomi e i loro Stipendio. Se hai bisogno di ottenere tutti questi dettagli in un'unica tabella, puoi usare VLOOKUP. Abbinerai ogni nome nella nuova Tabella C (Dove aveva il Nomi solo) con il nome corrispondente in FoglioB

Come abbiamo fatto?

In B2 della Tabella C, we used this Google Sheets formula to get the Dipartimenti dei dipendenti:

Dove:

A2 è la chiave di ricerca. FoglioA! è un riferimento a FoglioA con tabella A. A2:B4 è il nostro intervallo di ricerca su Foglio A. 2 è l'indice della colonna che vogliamo selezionare in A2:B4.

Su C2 di SheetC, use this Google Sheets formula to get the salary for the employees from FoglioB

Nota: Trascina la formula in altre celle per ottenere i loro valori.

Limitations of the VLOOKUP function and how to overcome

Diversi svantaggi derivano dall'uso della funzione VLOOKUP da sola. E se vuoi popolare l'intera colonna o riga senza farlo manualmente? E se i valori che stai cercando non sono unici? E se i valori che stai cercando non si trovano nella prima colonna del tuo intervallo?

There are two straightforward Google Sheets formulas to deal with these limitations. Let’s check them out!

Utilizzando le concatenazioni

Concatenations are a way of chaining up values of two or more cells into a single value. When your columns have values that are not unique, this can be problematic for the VLOOKUP function. Therefore, we will use concatenation to create unique columns for this function to work optimally.

There are several ways to concatenate with Google Sheets formula, but we will only focus on the easiest: using the ampersand ‘&.’ For example, to concatenate cells A12 e A15, basta usare =A12&A15 come formula.

Because we want to do this virtually for our VLOOKUP Google Sheets formula, we will apply it to our search keys and range. So, let’s create another table with the following values:

ABC
1NomeStatoStipendio
2EricColorado$40,500
3JaneConnecticut$37,600
4EricDelaware$30,000
5JohnCalifornia$52,000

If you try to duplicate or use VLOOKUP to populate another table with no unique values, the value of the first occurrence of the search key will be used throughout the search. Here’s an example of using the table above to reproduce the table. Check that the second Eric’s Stato e Stipendio non sono accurati.

To avoid IF errors, you can concatenate two cells or columns to make the key unique.

Per evitare tali errori, possiamo concatenare due celle o colonne per rendere la chiave unica, il che significa che avremo una maggiore possibilità di ottenere dati accurati. Abbiamo combinato il Nome e Stato per differenziare i due Eric in the list. Here’s the complete Google Sheets formula: 

=VLOOKUP(H10&I10, {D10&E10, F10}, 2, FALSE)
You can use VLOOKUP to populate another table with no unique values, the value of the first occurrence of the search key will be used throughout the search.

Did you see we used the curly brackets to get that? What does it mean? To solve the other limitation of the Google Sheets formula VLOOKUP, we introduced the concept of arrays to allow us to create a virtual table and change the order of these tables without creating them manually.

Quindi, ecco la seconda soluzione alla limitazione:

Utilizzando gli array

Cosa sono gli array in Google Sheets? If you have a background in coding, you should know what an array means. However, it may mean different when you use it in Google Sheets formula. Arrays are tables with columns or rows of values. 

Per differenziare una riga di valori da una colonna di valori in un array, si usa la virgola per rappresentare le colonne e il punto e virgola per rappresentare le righe. Se è confondente, ecco un esempio.

Se voglio rappresentare i nostri dati nell'ultima tabella in un array, una riga di Eric di Colorado sarà {Eric,Colorado,40500}. E le colonne di Nomi are represented as {Eric;Jane;Eric;John}.

Back to our usage above, after concatenating the Nomi e Stati, without arrays, you will need to create a Colonna di Supporto to hold the concatenation. So, that is where arrays help us. With the arrays, we can now create a virtual column and use the VLOOKUP Google Sheets formula to use that table to get us the results we want.

Pertanto, la tabella virtuale dall'array {D10&E10, F10} significa che la tabella unirà i valori di D10 e E10 in una colonna e aggiungi il valore di F10 alla colonna successiva. Quindi, la tabella di aiuto completa dovrebbe apparire così:

You need to create a Helper Column to hold the concatenation.

Come gestire gli errori nei risultati

Even when everything might seem right, sometimes errors might behave awkwardly in a Google Sheets formula. So, it is crucial to have a way to handle such issues. If you deal with a small dataset, you can find and fix the errors manually if it is well with you.

Un esempio di errore è il #N/A errore che si verifica quando la chiave di ricerca nella formula VLOOKUP non trova dati in una riga senza dati o quando la funzione FILTER non trova righe corrispondenti.

Fortunatamente, Google Sheets fornisce diverse formule per gestire tali errori. Ad esempio, l'IFNA troverà le celle con #N/A errors on your formula and replace them with a custom message. If you want to add zeros to such cells, here’s the Google Sheets formula:

Sintassi:

For example, the Google Sheets formula:

While this example may seem ideal, nesting multiple error-handling formulas can make your functions complicated. The good news is that there is an alternative: the IFERROR function, which is a sort of universal catch-all for errors.

The syntax and usage are just like IFNA; that is, the Google Sheets formula:

La nostra formula in azione: Unire due tabelle in Google Sheets

Ma ricordi la funzione FILTER che abbiamo introdotto prima? Dove si inserirà in questa formula?

To answer that, let me introduce you to another limitation of the VLOOKUP function we haven’t discussed. The VLOOKUP function does not automatically populate other cells with values— you need to copy and paste or drag the formulas to use them in other cells.

Ma questo è un altro lavoro che non vorrai fare. Quindi, come puoi superarlo? Ecco come puoi farlo:

Utilizzare la funzione FILTER per popolari i risultati di VLOOKUP

Utilizzando la funzione FILTER per filtrare i risultati di VLOOKUP con la condizione che l'intervallo non sia vuoto, sarai in grado di unire automaticamente le tue tabelle in Google Sheets.

In our example, our VLOOKUP function finds values from the range that we provided. The filter function will loop all the values for each cell in the VLOOKUP range until the condition becomes false; that is, when VLOOKUP returns nothing. The FILTER function then populates all the values received to their respective columns in our new table.

VLOOKUP Google Sheets formula finds values from the range that you provided.

As you have seen, we have joined three different tables using the VLOOKUP and FILTER functions. So, let’s now break down the formulas that we used:

La formula per ottenere Nome e Stato dalla Tabella 1:

Qui, stiamo filtrando l'intervallo della colonna da I10:I14 dall'intervallo I10 a K14 with VLOOKUP. Then we include an array index on the columns we want to pick from the range; that is, column index one and two, {1,2}: Nome e Stato.

La formula per ottenere Paese Preferito da Tabella 2:

Dal nostro intervallo M10:N10, vogliamo selezionare la seconda colonna (non da ordinare), e la nostra gamma di colonne M10:M14 non dovrebbe essere vuota secondo la nostra condizione FILTER.

Infine, la formula per ottenere ID e Codice Area da Tabella 3:

Riflessioni finali sulla query di Google Sheets per unire più tabelle

Merging two tables can be daunting, but with the functional Google Sheets formula that we shared to join your tables, we believe it’s now easier. By combining two powerful functions that we already know and use, the process is even clearer.

To merge different tables with a Google Sheets formula, use the following syntax:

Se trovi ancora una difficoltà nell'utilizzare queste formule, considera di usare Dataslayer per Google Sheets, che ti consente di unire facilmente due tabelle, importare dati da diversi fogli di calcolo e lavorare con oltre 40 fonti di dati diverse per il tuo reporting. Vuoi saperne di più? Inizia oggi gratuitamente!

COME POSSIAMO AIUTARTI?

MODULO DI CONTATTO

Siamo qui per aiutarti e rispondere a qualsiasi domanda tu possa avere. Non vediamo l'ora di ricevere tue notizie