How to sort only those rows which have no blank cell? - sorting

I have a Google Spreadsheet with two separate sheets. The first one is just a big list of names and data, and the second is supposed to be a sorted listing of all the data on the first sheet (sorted by, say, last name). Here is the current way I am defining the second sheet:
=sort(sheet1!A2:L100, sheet1!D2:D100, TRUE)
Which works fine for the most part, except for one issue: in sheet1, some of the cells in 4th column (column D) are blank. How can I change the formula so that the sorting ignores such rows which has a blank cell in column D?
The formulas i tried but got undesirable results :
=arrayformula(if(istext(sheet1!D2:D100), sort(sheet1!A2:L100, sheet1!D2:D100, true), ""))
It sorted as desired but with one issue - blank cells were not pushed at the end but scattered in between the rows.
=arrayformula(sort(filter(sheet1!A2:L100, istext(sheet1!D2:D100)),sheet1!D2:D100, true))
Though the filter part does its job perfectly but when coupled with sort, it is giving an error : Mismatched range lengths.

To filter out the rows with blank cells in column D, you could do something like #2, but as the error message suggested, the second argument would need to be filtered as well to ensure the ranges are the same length. Fortunately there is an easier way, and that is to use column indices rather than ranges:
=SORT(FILTER(sheet1!A2:L100;ISTEXT(sheet1!D2:D100));4;TRUE)
Alternatively you can use the QUERY function for this sort of thing:
=QUERY(sheet1!A2:L100;"select * where D != '' order by D";0)

For anyone looking this, the accepted answer works great if filtering out blank cells that are truly blank, but if the cells contain formulas that evaluate to blank (""), ISTEXT will evaluate to TRUE and blanks will not be filtered out. I modified the accepted answer slightly to work in my situation, in which I had cells containing formulas (that evaluated to "") that I wanted to filter out:
=SORT(FILTER(sheet1!A2:L100,sheet1!D2:D100 <> ""),4,TRUE)

Related

How do I FILTER cells based on two drop-down list conditions?

I need a FILTER formula to get an output of the cells within the range of the two labels matching the conditions from the two drop-down lists.
For example, given the below sheet, I need the output to be what's highlighted, given the two conditions from the drop-down lists:
I also need to be able to add more date rows, expanding downward.
I've tried using QUERY:
=TRANSPOSE(QUERY(Accounts!B2:F, "SELECT * WHERE B="""&B2&""" ",1))
This only gives me the row of contents (apple, carrot, cake, steak, soda).
Here you can find my solution:
https://docs.google.com/spreadsheets/d/1cWBLLmJx6mTlYrvPRvRE_y9NpBOJj_ILBgXmoB9suv4/copy
Note that when you merge cells, the value is only in the top one or the leftmost one. So if you have multiple rows for each data, you should multiplicate these cells.
I make additional column for this - first date I just copy and below it I insert a formula: (in H5)
=if(isblank(A5),H4,A5) - it says - if cell in column A is empty, take value from above, but if you find something there, put it here. Then I copy this formula down the sheet.
Then it gets easier.
To filter with data validation you have to first find right column using formulas INDEX and MATCH and then filter it against data values in additional column.
Does it work for you?

Getting error in split function inside array formula when using it with column title(array literal)

I am using these functions in my google sheets. With an array literal, I am getting an error when there are comma-separated inputs which need to be split but its working fine when there is only value in the K column. It's working fine without column title. Can someone explain the error in the first code?
={"Don't Edit this Column TargetGroup ID";Arrayformula(IFERROR(SPLIT(MainSheet!K2:K,",",TRUE, True),""))}
and
=Arrayformula(IFERROR(SPLIT(MainSheet!K2:K,",",TRUE, True),""))
Try this one:
={
"Don't Edit this Column TargetGroup ID", Arrayformula(SPLIT(REPT(",", COLUMNS(SPLIT(MainSheet!K2:K,",")) - 2), ",", True, False));
Arrayformula(IFERROR(SPLIT(MainSheet!K2:K,","),""))
}
You had only one string value for the first raw in you array literal ({}), so it is only one column.
Presumably, SPLIT found at least one comma and gave you a minimum of two column range which cannot be attached to that first row of yours (the header string) from the bottom as they do not match column-wise.
This SPLIT(REPT(...), ...) gives a needed number of empty cells to append to the right of your header so the number of columns will match.
If that is not the case then please provide a error message or, even better, share a sample sheet where this issued is reproduced.

Google Sheets split words then sort Alphabetically, Using arrayformula

I have multiple rows, containing varying number of cells, and in each cell I have one or more words.
I'm looking for a way to go row by row:
Splitting the multiple words into single word parts (with space (" ") as the delimiter)
Sort the parts alphabetically
Put the parts back into multiple word cells
Remove duplicates in the row
Already the first, seemingly easy part, gave me issues. Even if I just tried to look at one row, the closest I got was the code below and that inserted strange " " for the one word cells, and also failed to sort
=iferror(arrayformula(transpose(sort(transpose(SPLIT(transpose(B3:3)," "))))),"")
1
I also tried to cut, sort and join the above output using the Query Header trick, but it refuses so sort anything but the first row
=arrayformula(trim(transpose(query(SORT(transpose(B12:D)),,COLUMNS(B12:D)))))
2
I haven't even attempted combining the two things together, considering my epic fails above.
The final input document will have lots more rows and columns, so I also need to make sure this works without any hard coding of row or column numbers.
Any and all help would be greatly appreciated.
I might have something for you. It's a little bit of an odd way to do it, but it could work I think.
Take a look at this sheet.
The original data is in the Original tab in cells B3:J, all the way down.
The Converter tab puts every thing in one column, then there is a "dragdown formula" that'd need to be dragged down a long ways depending on how big your data set it is. The good news is that you can just do it for thousands of rows beforehad and it will remain blank.
the New Data tab has just one formula and will repopulate your data the way it was, but with the resorted words.
Try messing with the data on the Original Data tab as much as you want. see if New Data reflects what you'd want.

ArrayFormula column disappears when sorting in a filter view in Google Sheets

I'd like to use ArrayFormula to populate a column in spreadsheet, but when I Sort A->Z in a filter view, the ArrayFormula column vanishes. In some cases, the column includes a #REF! error about the range, and in some cases the column is just blank after the Sort. The following is a simplified version of what I'm trying to do (in my actual application, I'm doing a Vlookup to another sheet):
https://docs.google.com/spreadsheets/d/1XbqqedOjuSKuE-ZLIHNw59-r01EsNMpx7YVqOoxSOR4/edit?usp=sharing
The column 3 header uses an ArrayFormula to copy from column 1. If you go to the Filter 1 filter view, you'll note that column 3 is blank except for an error. This happens after I try to Sort Z->A on column 2. In my more complicated use-case, involving a Vlookup, after a Sort the column disappears entirely (leaving no #REF! error). Before sorting in both cases, everything is fine.
How do I make ArrayFormula values persist in filter views after sorting?
Thanks for your help!
I'm guessing that, because your references are normal (relative, not anchored/absolute), the range A2:A10 after sorting down turns into something absurd, like A7:A4, depending on actual sorted values.
Also, if you hover with your mouse on the #REF error, what does it tell you?
Anyway, try using absolute references in your formula:
=arrayformula({"Column 3"; A$2:A$10})
Edit
Fascinating. It's the first time I see this type of error. Taking it at face value, it seems that it's a limitation of Google Spreadsheets - you cannot use ARRAYFORMULAS spanning multiple rows inside sorted filter views, because, like I sort of guessed, it messes up the ARRAYFORMULA's range (as indicated by the fact that the formula is now in C4 instead of C1).
But that gives you also the solution: do not include the cell with the arrayformula in the filter view. Instead of making your filter view's target range A1:C20, make it A1:B20. Then the arrayformula in C1 will be untouched by the filter and will indeed continue to work.
I have found a solution for my usecase, in your case, it could be:
=arrayformula(if(row(C:C)=1;"Column 3";A:A))
But you'll need to consider the whole columns in your formulas.
Example
Have you tried A2:A?
If you don't put an ending row, means the end of the column.
It worked for me.
Cheers

How to filter entries that are not duplicates of entries from others columns in Google Sheets?

I have a column called "Masterlist" which contains values from Lists 1, 2 and 3. It also contains values which are present only in Masterlist.
How can I filter them, like shown at the attached image in Google Sheets?
EDIT: The lists will have more than one entries.
Solution 1
In E2, type in
=filter(A2:A,arrayformula(iserror(match(A2:A,B2:D2,0))))
Check the documentation of filter or match for how to use them. With match, be sure to include the third argument. That is an easy one to forget. arrayformula iterates a formula over a range. The output can be a range, in which case it will print over any un-written cells. When arrayformula interacts with match, it only iterates over the first argument, which is why this solution works.
EDIT: If you have a two-dimensional range to match to, you need to collapse them into a one-dimensional range using the concatenation operators such as
=filter(A2:A,arrayformula(iserror(match(A2:A,{B2:B4;C2:C4;D2:C4},0))))
You can experiment with endings without row indices and let Google Sheets select an ending index for you.
Solution 2
Use the native Filter View feature. Good for the scenarios where you don't need to separately print a list of the unique values in "masterlist".
Go to Data -> Create Filter View
Use the relevant help pages to navigate yourself. I can see a few ways to implement what you desire, including
filter by value on the same column (selecting the actual values manually);
filter by value on a "helper column" where you include a formula in the cells to check whether the content in "masterlist" belongs to the list you want to check against. You can use the match and iserror combo here;
custom formula using a similar formula as above.
If your column A, ie. the "masterlist", is something a user would add to, then Data Validation can be used to good effect in conjunction with Filter View.

Resources