Excel sorting and data matching - excel

I have a large excel sheet with many columns. I do not want to sort columns A - X. Column Z needs to be sorted so the values in column Z = values in column A (A55=Z55).
Column Y is related to column Z (Y22 related to Z22). So column Y and Z must maintain there relationship before and after the sort. Example Data:
Column A: A123, A456, A556, B234
Column Y: red, yellow, pink, green
Column Z: A556, A456, B234.
How do I sort column Z (and Y)?

Easiest Way:
My Array:
Add Column:
New Array(s):
Sort A smallest to largest (important!):
Sort Z smallest to largest:
Delete Temp Column and voila:

If you are fine with adding columns, then instead of directly sorting Y and Z we can essentially create 2 new columns that are the sorted values according to column A.
So if your data looks like this:
A ... Y Z
------------------------
A123 red A556
A456 yellow A456
A556 pink B234
B234 green A123
We can create this:
A ... Y Z AA AB
---------------------------------------
A123 red A556 A123 green
A456 yellow A456 A456 yellow
A556 pink B234 A556 red
B234 green A123 B234 pink
The formula for column AA would be a straight cell reference to column A:
=A1, =A2, =A3, etc.
The formula for column AB would be a simple index/match combination:
=INDEX(Y:Y,MATCH(AA1,Z:Z,0))
So it would look like this:
A ... Y Z AA AB
---------------------------------------------------------------
A123 red A556 =A1 =INDEX(Y:Y,MATCH(AA1,Z:Z,0))
A456 yellow A456 =A2 =INDEX(Y:Y,MATCH(AA2,Z:Z,0))
A556 pink B234 =A3 =INDEX(Y:Y,MATCH(AA3,Z:Z,0))
B234 green A123 =A4 =INDEX(Y:Y,MATCH(AA4,Z:Z,0))

Related

Use Name in lookup_array

Assuming I have the following data in the sheet.
A
B
1
RED
1
2
GREEN
2
3
BLUE
3
4
COLOR
1
And I define names for B1, B2, B3, and B4 as RED, GREEN, BLUE, and COLOR, respectively.
Next I'm using a formula like below
MATCH(COLOR, {RED, GREEN, BLUE})
but Excel said formula error. I tried MATCH(COLOR, {1, 2, 3}) and it's ok.
So the question is, what's the correct way to use Name in lookup array?

append to existing values if condition is true

I want to compare the values row by row from sheet1-colors with sheet2-darkcolors
if they are both matching append the row values d and e to the fruits column in sheet 1
basically
sheet1 colors |blue |=== sheet2 darkcolors |blue| ----> fruits+yummy+yuicy
sheet1
colors
fruits
blue
bananay
red
apple
green
kiwi
sheet2
darkcolors
d
e
blue
yummy
juicy
black
tummy
fruicy
green
tummy
goosy
result
colors
fruits
blue
banana+yummy+juicy
red
apple
green
kiwi+tummy+goosy
I tried using `IF` combined with `XLOOKUP` but could not get it running together
Try-
=IFERROR(TEXTJOIN("+",TRUE,B2,INDEX(TRANSPOSE(Sheet2!$B$2:$C$4),,MATCH(A2,Sheet2!A2:A4,0))),B2)

Excel: search value in array and fetch row and column name

I have a spreadsheet of available samples across 45 boxes, arranged stacked with column headers from 1 to 10 and row headers from A to J. I'm looking for a way to fetch the box, row and cell number if I lookup an ID (prefixed with B).
Sheet 1 is a list of animal IDs that I want to know if a sample is available for
Sheet 2:
Box 1
1 2 3 4 5 ... 10
A B43 B12 B3 B6 B103
B B13 B14 B78 B51 B63
C B78 B33 B99 B43 B92
...
J
Box 2
1 2 3 4 5 ... 10
A B2 B6
I have tried doing nested if functions by columns:
if(match(A2, Sheet2!$B$2:$B$521,0),"1",if(match(A2,Sheet2!$C$2:$C$521,0),"2","")
...but I've been getting #N/A if A2 is in column C.
I've resorted to re-labelling the left-most column to Box 1 A, Box 1 B, Box 1 C... so on, and doing:
=index(Sheet2!$A$2:$A$521,match(A2,Sheet2!$B$2:$B$521,0),0)
...and duplicating the function for **Columns 1 to 10*.
Sheet 1:
Animal ID Col1 Col2 Col3 Col4 ...
B12 . Box 1 A . .
B43 . . . Box 1 C
...
Is there an easier way to fetch the location of a sample from an array?
If your Sheet2 looks like this.
and you want the data like this in Sheet1.
Then enter this formula in Cell B2 of Sheet1 and drag it down and across.
=IFERROR(CONCATENATE(INDEX(Sheet2!$A:$A,(MATCH($A2,Sheet2!B:B,0))-MOD(MATCH($A2,Sheet2!B:B,0)-1,12),)," - ",INDEX(Sheet2!$A:$A,MATCH($A2,Sheet2!B:B,0))),".")

Count how many distinct values (or get list of distinct values) in a filtered column

Is there a way to count the number of distinct values in a filtered column in Excel?
Using the formula at https://exceljet.net/formula/count-unique-values-in-a-range-with-countif I can count the number of distinct values in a range, but when that range has been filtered with an auto-filter I still get the unfiltered count.
For example:
A B
1 Scarf Blue
2 Hat Red
3 Gloves Green
4 Coat Blue
5 Balloon Red
6 Shoes Blue
Counting unique values in B with =SUMPRODUCT((B1:B6<>"") / COUNTIF(B1:B6,B1:B6 & "")) should return 3 as the distinct values are Red, Green and Blue.
If I auto filter Column B to just select Red items, the resulting table will look like:
A B
2 Hat Red
5 Balloon Red
In this case the number of distinct values retuned should be 1. But the formula above still returns 3.
The formula should also cope with multiple selections in the auto-filter, so for example filtering for Blue and Green should result in the following table:
A B
1 Scarf Blue
3 Gloves Green
4 Coat Blue
6 Shoes Blue
From which the formula should return 2 (Blue, Green).
Finally, if I am filtering on column A rather than B, the formula should still work. So If I am only interested in Hat, Scarf and Coat, filtering column A for these values would result in:
A B
1 Scarf Blue
2 Hat Red
4 Coat Blue
From which the formula should return 2.
(I'm using Excel 2013 and need to do this in a formula rather than using VBA etc)
I also found this page on office.com which I thought might help, but alas I can't get it to work for me.
This reference shows how you can exclude hidden rows using AGGREGATE
Excluding hidden rows with AGGREGATE
You can then use a standard way of counting unique values like this
Counting unique values with FREQUENCY
So if you were counting values in column B, you would need a helper column (say C) containing
=IF(AGGREGATE(3,5,B2),B2,"")
Then plug in the form of count unique that ignores empty cells
=SUM(IF(FREQUENCY(IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""), IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""))>0,1))
Or your formula if you prefer
=SUMPRODUCT((C2:C10<>"") / COUNTIF(C2:C10,C2:C10 & ""))

How can I concatenate values in an Excel pivot, as opposed to summing or counting

Say I have the following data:
Col1 Col2
------------
Bob Green
Bob Green
Bob Green
Chris Blue
Chris Blue
Chris Red
Dave Blue
Dave Green
Dave Red
A default Pivot Table in Excel would yield:
Col1 Col2
------------
Bob Green
Chris Blue
Red
Dave Blue
Green
Red
Is there any way to concatenate on Col2 (specifically, with separators), so I end up with this?:
Col1 Col2
------------
Bob Green
Chris Blue,Red
Dave Blue,Green,Red
What you want is not possible from a PivotTable. However, if Bob is in A2 a formula in C2 like:
=IF(A1=A2,C1&", "&B2,B2)
and another in D2 of:
=A2=A3
both copied down to suit, may serve if you "fill in the gaps" (either in the PT or with Go To Special, Blanks, =, Up, Ctrl+Enter) then select all, Copy, Paste Special, Values over the top and filter to delete rows showing TRUE.
TEXTJOIN is now available on some versions.

Resources