Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Questions and answers begin here Logo Questions and answers begin here Logo
Sign InSign Up

Questions and answers begin here

Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Blog
  • Contact Us

Google Sheets – How can I flatten and split data while including multiple columns?

Home/ Questions/Q 377
Next
Answered
Google Sheets - How can I flatten and split data while including multiple columns?
art_of_gonso
art_of_gonso Begginer

I am trying to flatten and split data in Google Sheets while including multiple columns, but I’m not getting the desired output. I’ve been trying to use a formula I found online, but it’s not working as expected. Here’s what I have:
=ArrayFormula(
QUERY(
{Sheet1!A:B, SPLIT(Sheet1!C:C, ",")}
, "select Col1, Col2, Col3 where Col3 is not null")
)

The goal of this formula is to split the data in column C by commas and display it in separate rows while keeping the data in columns A and B intact. However, the formula is not returning the expected output. Instead of splitting the data in column C and displaying it in separate rows, the formula is combining it into one cell.
I have checked the syntax several times, and it appears to be correct. I have also tried tweaking the formula in different ways, but none of the tweaks have resulted in the desired output. I suspect that there may be something wrong with the data in column C itself, but I’m not sure what it could be. Any help in identifying the issue and fixing it would be greatly appreciated. Thanks in advance!

data manipulationdelimiter-separated valuesGoogle Sheetsspreadsheet formulastext parsing
  • 549
  • 0 Followers
  • 1
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    beyondthecrest Teacher
    2021-02-22T16:23:05+00:00Added an answer about 2 years ago

    Hello there! I understand that you’re facing a problem with flattening and splitting data in Google Sheets while including multiple columns. As an expert, I can tell you that the simplest and most efficient way to solve this problem is by using Google Apps Script.
    Firstly, you need to open the sheet where you want to flatten and split the data. Then, go to Tools > Script Editor. This will open the Google Apps Script editor. In the editor, replace the existing code with the following code snippet:
    “`javascript
    function flattenAndSplit() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var data = sheet.getDataRange().getValues();
    var newData = [];
    for (var i = 0; i < data.length; i++) { var row = data[i]; var split = row[0].split(","); for (var j = 0; j < split.length; j++) { newData.push([split[j], row[1], row[2]]); } } sheet.getRange(1, 4, newData.length, newData[0].length).setValues(newData); } ``` This script starts by getting the active sheet and then getting all the values from the sheet. It then creates a new empty array called newData that will store the flattened and split data. The script will then loop through each row of the data, split the first column (assuming the data is in columns A, B, and C), and push the split values along with corresponding columns B and C values into the newData array. After the newData array is created, the script will write the flattened and split data to a new range (assuming you want the flattened and split data in columns D, E, and F). The setValues method is used to write the data to the sheet. Once you have replaced the code in the script editor with the above code, you can run the script by clicking on Run > flattenAndSplit. This will execute the script and generate the flattened and split data.
    In conclusion, the above script is a simple and efficient way to flatten and split data in Google Sheets while including multiple columns. I hope that this solution helps you with your problem. If you have any further questions, please feel free to ask me.

    • 177
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. vinniie23 Teacher
    2021-02-28T18:56:12+00:00Added an answer about 2 years ago

    To solve this problem, you can try using Google script to flatten and split the data while including multiple columns in a Google Sheets. The Google script can help you automate the process and enable you to save time and focus on other tasks.
    To do this, you can start by opening the Google Sheets where you want to apply the script. Then, click on the “Tools” option from the menu and select “Script editor”. This will open a new tab with the Google script editor.
    Next, copy and paste the script code into the editor, and save it by clicking on the “Save” icon. After that, close the editor tab and return to your Google Sheets’ tab.
    To execute the script, click on the “Run” option from the “Add-ons” menu, and select “script name”. This will run the script and the flattened and split data will be displayed in the next sheet.

    Overall, using Google script is a powerful way to automate your workflow and increase your productivity. With a little bit of practice and experimentation, you can create complex scripts that perform a wide range of tasks and save you considerable time and effort.

    • 69
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. alikhantokenov
    2021-02-28T21:57:08+00:00Added an answer about 2 years ago

    One solution to your problem of flattening and splitting data including multiple columns is by using the TRANSPOSE and QUERY functions in Google Sheets. First, transpose the data that you want to split and flatten, so that the rows become columns and vice versa. You can do this by selecting the data, copying it, and then right-clicking on another cell and selecting the “Transpose” option.

    Next, use the QUERY function to select the data that you want to split and flatten. You can specify the columns that you want to include in your query and use the “split” function to split the data based on a delimiter. For example:

    =QUERY(TRANSPOSE(A1:C6),”SELECT Col1, SPLIT(Col3,’, ‘) WHERE Col2 <> ””,0)

    In this example, we are selecting the first and third columns (Col1 and Col3) and splitting the third column based on commas. We are also excluding rows where the second column (Col2) is blank.

    Using the combination of the transpose and query functions, you can split and flatten your data in a way that includes multiple columns. This solution works well for a variety of data types and can be customized to fit your specific needs.

    • 50
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.