Google Spreadsheet Re order Columns - google-sheets

I'll explain an example of the situation before I ask the question.
If I have a pile of 5 numbered boxes and I scan them into a spreadsheet in the following order. 4,2,3,5,1
I copy that list into another program which adds more info to each number (which is what I want) but messes up the order. So now it is 3A,4D,1C,2B,5E.
Is there a formula I can use to reorder my new list to the original? I want to keep the original order as I print labels for these boxes and this would keep the order, meaning ordering both numerically won't work.
Thanks,
Graeme

I'd recommend an HLookup. Look for the character in your original list and add "*" which is a wild card for the second character.
Assumptions:
The first character is unique in the set.
Each value is in its own cell.
The original list is retained after intermediate program runs.

Related

How do I create a formula that recommends a matchup of 2 names?

Iโ€™m trying to make a formula that accomplishes this:
From a list of numbers, find the pairs of numbers with the lowest difference and second lowest difference, and write their differences elsewhere(I donโ€™t know how to do this)
Use those numbers to find and use the value(a name)of the cell to their left(I donโ€™t know how to do this with duplicate numbers)
How would I go about this?
The final product should include all 4 numbers, names, and both differences.
In the picture below, the pink shaded section is the goal.
What I did is to first SORT the values:
=SORT(A2:B,2,1)
Then, wrapped it in LAMBDA (in order not to repeat those formula again and again), and started "scanning" those values to find the differences. Since it's already sorted, the "smallest" will be found in this comparison.
For this, I used MAP. Used SEQUENCE, COUNTA and INDEX in order to find the amount of values in the first column; and SEQUENCE will help me do the "navigation". With the variable resultant "p" I searched each row with the next one (p+1). Resulting in something like this:
=LAMBDA(sorted,MAP(SEQUENCE(COUNTA(INDEX(sorted,,1))-1),LAMBDA(p,{INDEX(sorted,p,1),INDEX(sorted,p+1,1),INDEX(sorted,p+1,2)-INDEX(sorted,p,2)})))(SORT(A2:B,2,1))
With that, you're already one step away. Just with SORTN you can find the four smallest differences:
=LAMBDA(diff,SORTN(diff,4,1,3,1))
(LAMBDA(sorted,MAP(SEQUENCE(COUNTA(INDEX(sorted,,1))-1),LAMBDA(p,{INDEX(sorted,p,1),INDEX(sorted,p+1,1),INDEX(sorted,p+1,2)-INDEX(sorted,p,2)})))
(SORT(A2:B,2,1)))
I hope it's already useful! You can split those values in two columns, obviously; just using INDEX to access the desired row of this formula; or just locate the formula somewhere and refer to those cells. Let me know if it's useful!
you can try:
=LAMBDA(z,SORTN(MAP(INDEX(z,,1),INDEX(z,,2),LAMBDA(a,b,{a,b,ABS(XLOOKUP(a,A:A,B:B,)-XLOOKUP(b,A:A,B:B,))})),4,0,3,1))(INDEX(SPLIT(QUERY(UNIQUE(MAP(LAMBDA(z,FLATTEN(z& "๐Ÿ " &TRANSPOSE(z)))(FILTER(A2:A, A2:A<>"")),LAMBDA(y,JOIN("๐Ÿ ",SORT(UNIQUE(TRANSPOSE(SPLIT(y,"๐Ÿ ")))))))),"Select Col1 Where Col1 CONTAINS '๐Ÿ '"),"๐Ÿ ")))

Google Sheets: Displaying Data from one column into new column of MERGED cells

Using names listed in 1 column, I need to redisplay the same list of names in several sheets to filter info and add more info. It's a very complicated Google Sheet, otherwise I'd share it. I thought I'd make a model sheet, but the model sheet is doing exactly what I want:
model works wonderfully
=TRANSPOSE(SPLIT(JOIN("---",FILTER(A2:A,ISTEXT(A2:A))),"-",TRUE,FALSE))
Column C is the original problem, which seeks out the first, fourth, seventh etc. because the resulting fields are merged at those points.
Column D is the attempted solution, which takes all the fields, adds buffer punctuation between each ("-"), and then splits them transposed.
I tried the exact same equation in my convoluted sheet, but the original problem is still there:
actual references other sheet data and does not work
=TRANSPOSE(SPLIT(JOIN("---",FILTER('REHEARSAL ATTENDANCE'!B4:B,ISTEXT('REHEARSAL ATTENDANCE'!B4:B))),"-",TRUE,FALSE))
Is there a reason why it doesn't work?? I need them spaced out.
Solution:
Since your entries are spaced five cells apart instead of three in the model, you would need five dashes / repetitions as well.
=TRANSPOSE(SPLIT(JOIN("-----",FILTER('REHEARSAL ATTENDANCE'!B4:B,ISTEXT('REHEARSAL ATTENDANCE'!B4:B))),"-",TRUE,FALSE))

Automated Number Distribution in Spreadsheets

Beginner here!
Here's a spreadsheet trying to show what I mean.
Suppose I have data for metrics in comparison to my competitors.
The metrics are sorted highest to lowest and I want to turn the names of the other companies into "Company 1, Company 2, etc." along with the order of the metrics. Myself ("Me") remains unchanged.
With every data set the competitors could be different companies, and I could be ranked in a different position. The number of competitors could range from 1-20.
Is there a way to automate the green fields in the spreadsheet so that I can just paste the data and the competitor numbering stays constant no matter where I appear in the list?
Thank you!
Lighter Torches, I've added a sheet named "Erik" to your spreadsheet.
I've placed an array formula into two cells: G5 and J5. They are the same except for the relative cell references. Since it is an array formula, the single formula in G5 "runs" the entire data set generated in G5:H; likewise, the formula in J5 "runs" the entire data set generated in J5:K. Array formulas do not require dragging/copying to other cells.
Here is the G5 formula:
=ArrayFormula(QUERY(SPLIT({"Me"&"^"&IFERROR(VLOOKUP("Me",A5:B,2,FALSE),"NA");"Company "&ROW(INDIRECT("A1:A"&COUNTA(FILTER(A5:A,A5:A<>"",A5:A<>"Me"))))&"^"&SORT(FILTER(B5:B,A5:A<>"",A5:A<>"Me"),FILTER(B5:B,A5:A<>"",A5:A<>"Me"),FALSE)},"^"),"Select * Order By Col2 Desc"))
In your sample data, the companies are already ordered by rank, best to worst. But in the real world, it seems that may not always be the case. With that in mind, you'll notice that I moved your top performer to the bottom in the second data set. I've written the formulas to account for this (i.e., they will order the companies in the correct order whether they were originally in the correct order or not).
Also, if "Me" for some reason doesn't appear in a raw-data list at all, it still shows up, unranked, at the top of the generated list. Again, I tried to account for real-world what-ifs in the formula.
Finally, I added a sheet-wide custom Conditional Formatting rule that applies bold to any occurrence of the word "Me," since it seemed you were doing that manually. As such, you can type the sole word "Me" in any cell in the sheet, and it will automatically be formatted bold. You can see this rule by selecting Format > Conditional Formatting from the menu, then clicking on the rule you see in the window that appears.

How to count NUMBERS from google sheets when there is also a word there which doesn't need counting

Can't find a function which allows me to count the numbers, add them up and then paste it onto the first row. As there are also words there, for description of what is being counted then I've not yet found a way to count numbers without the words becoming a source of error.
Already tried the use of different functions
Fix my table so i can start counting how many things i do in a day/year
How it should look like
Finished code in the sheet, big thanks to pnuts
Try something like:
=sum(ArrayFormula(iferror(1*REGEXEXTRACT(A1:A4,"\d+"),0)))
and if you have cells in the selected range that are Number format and want those included in the addition, add those as well as a separate clause (ie append +sum(A1:A4)).

Stacking multiple columns on to one?

I am using Google SpreadSheet, and I'm trying to have multiple sheets containg a list of words. On the final sheet, I would like to create a summative list, which is a combination of all the values in the column. I got it sort working using =CONCATENATE() , but it turned it into a string. Any way to keep it as a column list?
Here is an example as columns:
Sheet1
apple
orange
banana
Sheet2
pineapple
strawberry
peach
FinalSheet
apple
orange
banana
pineapple
strawberry
peach
Updated Answer
I was right there is a much better solution. It's been posted below but I'm copying it here so it's in the top answer:
=unique({A:A;B:B})
Caveat: This will include one blank cell in certain scenarios (such as if there's one at the end of the first list).
If you're not concerned with ordering and a tailing blank cell a simple sort() will clean things up:
=sort(unique({A:A;B:B}))
Otherwise a filter() can remove the blanks like so:
=filter(unique({A:A;B:B}),NOT(ISBLANK(unique({A:A;B:B}))))
The following is the old deprecated answer
I'm confident that this is "The Wrong Way To Do It", as this seems such an absurdly simple and common task that I feel I must be missing something as it should not require such an overwrought solution.
But this works:
=UNIQUE(TRANSPOSE(SPLIT(JOIN(";",A:A,B:B),";")))
If your data contains any ';' characters you'll naturally need to change the delimiter.
The basic way, is just to do it as arrays like so
={A1:A10;B1:B10...etc}
The problem with this method, as I found out is that its very time consuming if you have lots of columns.
I've done some searching around and have come across this article:
Joining Multiple Columns Into One Sorted Column in Google Spreadsheets
The core formula is
=transpose(split(arrayformula(concatenate(if(len(A:Z)>0,A:Z&";",""))),";"))
Obviously you'd replace the A:Z to whatever range you want to use.
And if you want to do some sorting or removing duplicates, you'd simply wrap the the above formula in a SORT() and/or UNIQUE() method, like so..
=sort(unique(transpose(split(arrayformula(concatenate(if(len(A:Z)>0,A:Z&";",""))),";"))))
Hope this helps.
Happy coding everyone :)
You can use this:
=unique({A1:A;B1:B})
Works perfect here!
The unique() function gets rid of blank spaces, but wasn't helpful for me because some of my rows repeat. Instead I first filter the columns by len() to remove blank cells. Then I combine the columns together in the same way.
={filter(A:A, len(A:A)); filter(B:B, len(B:B))}
Much more simple:
={sheetone!A2:A;sheettwo!A2:A}
Use flatten, e.g. flatten(A1:B2). More details in this article.
If the 2d range is not in one piece, one can be created first with the ampersand or similar techniques. Afterwards flatten can be called on the resulting 2d range. The below example is a bit overkill but it is nice when working with dynamic 2d ranges, where the basic solution can't be easily used.
flatten(ARRAYFORMULA(SPLIT(ARRAYFORMULA(A1:A2&";"&C3:C4), ";")))
The article shows also how to easily unflatten a range using the, as well undocumented, skipping clause in a query.
=TRANSPOSE(SPLIT(TEXTJOIN("#",TRUE,TRANSPOSE(A:C),TRANSPOSE(D1:D5)),"#",FALSE,FALSE))
use a preferred delimiter absent in the data (instead of #) if needed
the first 1 (TRUE) parameter means IGNORE EMPTY, which is very important in this case..
the A:C and D1:D5 are the ranges to combine
all values remain there - not using UNIQUE
Try using your CONCATENATE argument with
=ArrayFormula(EXPAND(...))

Resources